From: Joel Pearson Date: 2012-10-25T08:17:30+09:00 Subject: Re: Exception handelling in ruby Brian Candler wrote in post #1080999: > Joel Pearson wrote in post #1080729: >> rescue => e >> This rescues any error and lets you use 'e' as a variable to inspect the >> error. > > That is incorrect. > > rescue => e > > only rescues exceptions which are StandardError and its descendants. > That is, it is exactly the same as > > rescue StandardError => e > >> something like the below would catch errors 1 and 2 respectively, and if >> the error didn't fall into those categories then the third rescue would >> catch it. >> >> rescue 1 >> rescue 2 >> rescue > > No, a bare "rescue" also only captures StandardError and its children. > > If you want to rescue *absolutely every* exception then you need to > write explicitly: > > rescue Exception > > However, as I said before, this is almost always a bad idea, because > exceptions outside of StandardError are things you rarely want to catch; > things that mean your interpreter has blown up in such a bad way that > it's pointless attempting to continue, and catching it will only prolong > the pain. D'oh! I forgot that Exception covers more than the default rescue. Brian is right, try to avoid rescuing something as all-encompassing as "Exception". If you want to know what your error is, you can do a test run which causes the failure, and try something like "e.class" to ascertain the type of error you need to handle. -- Posted via http://www.ruby-forum.com/.