Exception handling doesn't work

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?

Thanks for your time & Best Regards

Panagiotis A.

On 08/08/2012 12:14 PM, Panagiotis A. wrote:

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

Hello,

On 8 Αυγ 2012, at 22:23 , Justin C. [email protected] wrote:

“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.

Thanks for the prompt reply! It worked fine! :slight_smile:

-Justin

Panagiotis A.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs