From: Justin Collins Date: 2012-08-09T04:23:18+09:00 Subject: Re: Exception handling doesn't work On 08/08/2012 12:14 PM, Panagiotis Atmatzidis wrote: > Hello, > > I'm trying to handle an two different exception cases. Using the 'twitter' gem I have the two following exceptions. > > Here is the code: https://gist.github.com/3297666 > > Using irb (ruby 1.9.3x) I get : > > "Twitter::Error::ClientError" - when no internet connection is available and > "Twitter::Error::NotFound" - when username is not found, the supplied twitter username does not exist. > > However, no matter what the program goes with the 1st exception. Even when the error is "Twitter::Error::NotFound". > > What am I doing wrong? > You are not doing anything wrong. This is happening because Twitter::Error::NotFound inherits from Twitter::Error::ClientError and `rescue` will rescue any subclasses of the provided class. Try reversing the order of your rescue clauses. -Justin