How to do group Exception classes?

Hi, I’ve some exception that I want to group into “AuthError” class so I
do a “raise” for the specific child exception or for the parent class.
Is the
following correct?

module Auth

class GenericError < StandardError

class WrongPassword < GenericError

class ExpiredAccount < GenericError


so now I can do:

raise Auth::WrongPassword
rescue Auth::GenericError => e
puts “Exception class rescued: #{e.class}”

=> Exception class rescued: Auth::WrongPassword

This is: I didn’t do a “rescue” for Auth::WrongPassword, but for
But since Auth::WrongPassword is a child of Auth::GenericError then the
is executed and “e” is Auth::WrongPassword.

Do you suggest a better way of doing it? Thanks a lot for any

Hi Folks,

I am attempting to search a file for a specific string, and upon
locating said string, replace the line containing the string with a
new string. No amount of reading, testing, Googling enlightened me on
how this task is accomplished using Ruby.

If this is easy in Ruby I’ll proceed to start crying now because I
found my book and related internet resources woefully inadequate :frowning:
Any help/feedback/pointers/useful links would be greatly appreciated.



Documentation :

contents =“filename”) #read
contents.gsub!(“what you look for”, “the substitutive”) # modify“filename”, “rw”) { |file| file << contents } #write

Warning: will bring the whole file to memory.

Emmanuel O.
ELC Technologies ™
1921 State Street
Santa Barbara, CA 93101
[email protected]

(866)863-7365 Tel
(866)893-1902 Fax

+44 (0) 20 7504 1346 Tel - London Office
+44 (0) 20 7504 1347 Fax - London Office

Emmanuel, thank you very much for sorting me out. I can see I was
close but very confused on the write step.

Quoting Emmanuel O. [email protected]: