From: Stefan Lang Date: 2008-10-11T00:23:45+09:00 Subject: Re: rescue clause 2008/10/10 Patrick Doyle : > I have been looking at the source code for rake (as you can probably tell > from my previous questions), in an attempt to study a reasonable sized Ruby > application and see what I can learn from the exercise. I've come across > something that looks like it could be an innocuous typo in the code, or it > could be doing something that I just don't understand. Here is the code > snippet: > > def standard_exception_handling > begin > yield > rescue SystemExit => ex > # Exit silently with current status > exit(ex.status) > rescue SystemExit, OptionParser::InvalidOption => ex > # Exit silently > exit(1) > end > end > > I am curious as to why SystemExit shows up in 2 different rescue clauses. > Is that a typo? Or is something else going on? The the first rescue clause and the SystemExit in the second clause can be removed without changing the semantics of the code. As a sidenote, something being popular does not necessarily mean it should be used as a model for good Ruby code. Sometimes the techniques used only make sense in a historical context. Stefan