I’m writing a C++ program that has a Ruby interpreter embedded in it.
I’d like to keep all Ruby-related exceptions contained within the Ruby
runtime so that I don’t have to protect all my calls. Since native
objects can be subclassed by Ruby, you never know when a call is going
to result in the interpreter doing something.
To contain the exceptions, I’ve overridden Kernel#raise, like this:
alias _raise raise
if a.size == 0
elsif a.size == 1
rescue Exception => e
$stderr.print e.class, ": ", e.message, “\n”
$stderr.puts e.backtrace unless e.backtrace.nil?
I can’t shake the feeling that this is dirty and that there must be a
better way to do things. Just hoping to get some feedback on both the
concept and implementation.