[…]
… Is there a way to put one begin/end block encompassing the whole
class/object? Sort of like an instance-wide begin/end block?
There isn’t any syntax that lets you rescue any exception for the whole
class, but you can add a rescue clause to an entire method, saving you a
‘begin’ and an ‘end’. E.g., instead of:
def one(stext)
begin
puts(“Hi”);
rescue Exception => msg
self.exceptionHandle(msg)
end
end
you’d have:
def one(stext)
puts(“Hi”);
rescue Exception => msg
self.exceptionHandle(msg)
end
This is (IMO) far more readable than the alternative.
You could probably add exception-handling for any method on a whole
class using clever aliasing and the ‘method_added’ hook or a
declarative, but down that path lies madness in the face of ScriptErrors
or any exception you haven’t anticipated.