I
Iñaki Baz Castillo
Hi, I've some exception that I want to group into "AuthError" class so I ca=
n=20
do a "raise" for the specific child exception or for the parent class. Is t=
he=20
following correct?
=2D--------------------------
module Auth
class GenericError < StandardError
end
class WrongPassword < GenericError
end
class ExpiredAccount < GenericError
end
end
=2D---------------------------
so now I can do:
=2D---------------------------
begin
raise Auth::WrongPassword
rescue Auth::GenericError =3D> e
puts "Exception class rescued: #{e.class}"
end
=3D> Exception class rescued: Auth::WrongPassword
=2D---------------------------
This is: I didn't do a "rescue" for Auth::WrongPassword, but for=20
Auth::GenericError.
But since Auth::WrongPassword is a child of Auth::GenericError then the res=
cue=20
is executed and "e" is Auth::WrongPassword.
Do you suggest a better way of doing it? Thanks a lot for any suggestion.
=2D-=20
I=C3=B1aki Baz Castillo
n=20
do a "raise" for the specific child exception or for the parent class. Is t=
he=20
following correct?
=2D--------------------------
module Auth
class GenericError < StandardError
end
class WrongPassword < GenericError
end
class ExpiredAccount < GenericError
end
end
=2D---------------------------
so now I can do:
=2D---------------------------
begin
raise Auth::WrongPassword
rescue Auth::GenericError =3D> e
puts "Exception class rescued: #{e.class}"
end
=3D> Exception class rescued: Auth::WrongPassword
=2D---------------------------
This is: I didn't do a "rescue" for Auth::WrongPassword, but for=20
Auth::GenericError.
But since Auth::WrongPassword is a child of Auth::GenericError then the res=
cue=20
is executed and "e" is Auth::WrongPassword.
Do you suggest a better way of doing it? Thanks a lot for any suggestion.
=2D-=20
I=C3=B1aki Baz Castillo