From: Holden Glova Date: 2002-02-11T18:49:36+09:00 Subject: Re: handling errors -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, 11 Feb 2002 22:09, Tobias Reif wrote: > Hi, > > somehow I had this working. > > --- > class Doc > def make > "Content-type: image/svg+xml\n\n"+ > '' > h.l > end > end > > doc = Doc.new > > begin > puts doc.make > rescue > print "Content-type: text/plain\n\n" > puts 'myself speaking: ' +$! > end > --- > > with the erratic fifth line, I get > --- > err.rb:6:in `make': undefined local variable or method `h' for > # > (NameError) > from err.rb:13 > --- > > instead of > --- > Content-type: text/plain > > myself speaking: [...] > --- > > Tobi I don't know if you can do that without specifying an exception type? Anyhow I have never done it like that. Do you want to rescue any type of exception? The code below will do that. synack@eugene:~$ ruby demo.rb Content-type: text/plain myself speaking: undefined local variable or method `h' for # synack@eugene:~$ cat demo.rb class Doc def make "Content-type: image/svg+xml\n\n"+ '' h.l end end doc = Doc.new begin puts doc.make rescue Exception # <-- Catch all Exceptions print "Content-type: text/plain\n\n" puts 'myself speaking: ' +$! end - -- Signed, Holden Glova -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8Z5Ss+mF116Lw2cQRAo4yAKCCtbtmmbAHAMX4ue37pdWdo26ZxACZAb5v gYxCioXrDkZSriKY+dTkoIQ= =sDRn -----END PGP SIGNATURE-----