[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

rescue clause

Patrick Doyle

10/10/2008 1:50:00 PM

[Note: parts of this message were removed to make it a legal post.]

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?

--wpd

4 Answers

Sandro Paganotti

10/10/2008 3:03:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

The difference seems to be in that ' OptionParser::InvalidOption ' token
but it's the first time I saw a begin-rescue block of this kind.



On Fri, Oct 10, 2008 at 1:50 PM, Patrick Doyle <wpdster@gmail.com> wrote:

> 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?
>
> --wpd
>



--
Go outside! The graphics are amazing!

Stefan Lang

10/10/2008 3:24:00 PM

0

2008/10/10 Patrick Doyle <wpdster@gmail.com>:
> 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

Patrick Doyle

10/10/2008 3:43:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

>
>
> 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
>
> In order to shorten my email, I left out the rest of the code, which reads:

rescue Exception => ex
# Exit with error message
$stderr.puts "rake aborted!"
$stderr.puts ex.message
if options.trace
$stderr.puts ex.backtrace.join("\n")
else
$stderr.puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } ||
""
$stderr.puts "(See full trace by running task with --trace)"
end
exit(1)

Because the code continues on to rescue Exception (which is the ancestor of
all exceptions), the code does need to rescue SystemExit separately (and
before, I believe) Exception.

Is there a historical reason why the second rescue clause contains
SystemExit and OptionParser::InvalidOption. I understand your point about
what makes a good model for Ruby code. In my case, having used makefiles
for decades, and having been quite comfortable with them (most of the time),
I am looking at rake and saying "what's in it for me?" So far, the answer
has been, "Oh, that's cool! This feature and that feature certainly would
make my life easier. Hmmm... I wonder how (s)he did that?" at which point
I start to explore.

Having the historical "proto_rake.rb" file and seeing the power of that
simple script, and seeing to where it has evolved at this point in time, is
also educational.

--wpd

r

4/19/2014 12:52:00 PM

0

In article <ndo4l9h1e60dmc5jipbk4je62lpqovbkk0@4ax.com>, NoBody
<NoBody@nowhere.com> wrote:

> On Fri, 18 Apr 2014 07:55:45 -0700, r@somis.org (?RLMeasures) wrote:
>
> >In article <0g12l956n19qsgoghntpihtursk1e48cnv@4ax.com>, NoBody
> ><NoBody@nowhere.com> wrote:
> >
> >> On Thu, 17 Apr 2014 06:43:33 -0700, r@somis.org (?RLMeasures) wrote:
> >>
> >> >In article <agbvk993q1ch366bh8n1r5ej76d9hp1h9g@4ax.com>, NoBody
> >> ><NoBody@nowhere.com> wrote:
> >> >
> >> >> On Wed, 16 Apr 2014 13:38:02 -0700, r@somis.org (?RLMeasures) wrote:
> >> >>
> >> >> >In article <lvnsk95cgfj7d4rkm6t3piv34sft520718@4ax.com>, NoBody
> >> >> ><NoBody@nowhere.com> wrote:
> >> >> >
> >> >> >> On Tue, 15 Apr 2014 05:41:09 -0700, r@somis.org (?RLMeasures) wrote:
> >> >> >>
> >> >> >> >In article <353qk9lv483aeogtr1gcs4fig2u32ckujo@4ax.com>, NoBody
> >> >> >> ><NoBody@nowhere.com> wrote:
> >> >> >> >
> >> >> >> >> On Mon, 14 Apr 2014 13:31:26 -0700, r@somis.org
(?RLMeasures) wrote:
> >> >> >> >>
> >> >> >> >> >In article <4hfnk9tgmpibf1hbrot5k5033obacl4umk@4ax.com>, NoBody
> >> >> >> >> ><NoBody@nowhere.com> wrote:
> >> >> >> >> >
> >> >> >> >> >> On Sun, 13 Apr 2014 18:37:36 -0700, r@somis.org
> >(?RLMeasures) wrote:
> >> >> >> >> >>
> >> >> >> >> >> >In article <ngilk9drc60g7r47dtlm9rkv94j0m863v2@4ax.com>,
PATRICK
> >> >> >> >> >> ><pbarker001@woh.rr.com> wrote:
> >> >> >> >> >> >
> >> >> >> >> >> >> On Sun, 13 Apr 2014 09:37:49 -0700, r@somis.org
> >> >(?RLMeasures) wrote:
> >> >> >> >> >> >>
> >> >> >> >> >> >> >In article <m43lk9h82q7b0ur9ftcu8hd2beer7l0e3h@4ax.com>,
> >NoBody
> >> >> >> >> >> >> ><NoBody@nowhere.com> wrote:
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> On Sat, 12 Apr 2014 19:46:22 -0700, r@somis.org
> >> >> >(?RLMeasures) wrote:
> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >In article <lic0i2$9nt$1@news.xmission.com>,
> >> >> >> >gazelle@shell.xmission.com
> >> >> >> >> >> >> >> >(Kenny McCormack) wrote:
> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >> In article <120420141214553292%nope@noway.com>, A
> >Friend <A
> >> >> >> >> >> >Friend> wrote:
> >> >> >> >> >> >> >> >> >In article <libftf$u6t$2@news.xmission.com>, Kenny
> >> >McCormack
> >> >> >> >> >> >> >> >> ><gazelle@shell.xmission.com> wrote:
> >> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >> >> In article
> ><m4gik9lh4k1m4i6i67i4569ondl8nn4m4l@4ax.com>,
> >> >> >> >> >> >> >> >> >> NoBody <NoBody@nowhere.com> wrote:
> >> >> >> >> >> >> >> >> >> ...
> >> >> >> >> >> >> >> >> >> >You continue to amuse me. Thanks!
> >> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> >> And vice versa. I.e., you haven't made it into my
> >> >> >> >killfile yet...
> >> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >> >He's made it into mine. He does nothing but spew
> >brainless
> >> >> >> >> >bullshit,
> >> >> >> >> >> >> >> >> >and when you finally get tired of him and stop
> >responding,
> >> >> >> >he cries
> >> >> >> >> >> >> >> >> >"Silence! Just as I expected!" There's no point
> >in dealing
> >> >> >> >> >with him.
> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> Oh, agreed. But it still makes for amusing reading.
> >> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> >> I leave to RL to actually respond to him. He seems to
> >> >> >enjoy his
> >> >> >> >> >> >assigned
> >> >> >> >> >> >> >> >> task.
> >> >> >> >> >> >> >> >
> >> >> >> >> >> >> >> >? History deniers are a source of enjoyment.
> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> What history is that? Are you referring to the
encyclical
> >> >> >you claim
> >> >> >> >> >> >> >> exist but can't show that it does?
> >> >> >> >> >> >> >>
> >> >> >> >> >> >> >> What is truly funny, is that that you guys seem to be
> >> >> >high-fiving RL
> >> >> >> >> >> >> >> for lying outright.
> >> >> >> >> >> >> >
> >> >> >> >> >> >> >? that's because they know who shoots blanks and who
> >doesn't.
> >> >> >> >. . That
> >> >> >> >> >> >> >in 1866 Pius IX would assume it was impossible for a
> >genuine RC
> >> >> >> >priest to
> >> >> >> >> >> >> >sodomize RC altar- boys seems reasonable because at
> >first I had
> >> >> >> >mistakenly
> >> >> >> >> >> >> >assumed the same thing.
> >> >> >> >> >> >>
> >> >> >> >> >> >> And then you FURTHER assume that he wrote a "secret"
> >> >encyclical that
> >> >> >> >> >> >> only a few of you know about. You really are special,
> >aren't you?
> >> >> >> >> >> >
> >> >> >> >> >> >? hardly PB. I'm just a guy who watched the HBO
documentary and
> >> >> >realized
> >> >> >> >> >>
> >> >> >> >> >> That documentary for which you provided a dead link?
BWWAAAAAA!
> >> >> >> >> >
> >> >> >> >> >? zzz
> >> >> >> >>
> >> >> >> >> Your surrender is so noted.
> >> >> >> >
> >> >> >> >? You seem to have already forgotten that I watched the HBO
> >documentary.
> >> >> >>
> >> >> >> The documentary you have failed to show exists? ??? Good one.
> >> >> >> If it exists, from where did they get their information?
> >> >> >
> >> >> >? HBO knows. I do not.
> >> >>
> >> >> Show the documentary existed. Broken links are not proof. Provide
> >> >> the name and IMDB reference.
> >> >
> >> >? zzz
> >>
> >> Translation: RL is a liar.
> >>
> >> >>
> >> >> >
> >> >> >>Do you
> >> >> >> believe everything you see on TV?
> >> >> >>
> >> >> >? chortle. Get serious.
> >> >>
> >> >> Right, you only believe what fits into your narrow, bigotted view of
> >> >> the world.
> >> >
> >> >? my view is not influenced by the Church of Rome. Your's is.
> >>
> >> Your "view" is not based on any form of facts. You decide what your
> >> reality is. One only needs your posts about encyclicals that never
> >> existed.
> >
> >? "It ain't what you don't know that gets you into trouble. It's what you
> >know for sure that just ain't so."
> > ? Mark Twain
>
> There goes that irony bell again as you avoid your lie.

? SOS