J
J. B. Rainsberger
Everyone:
Being a Java programmer learning Ruby, I don't want my Java-based
prejudices about design pollute my thinking as I make the transition to
being a fluent Ruby speaker. Accordingly, I'd like you to suggest to me
how I should design my exception classes.
I Googled around for about 10 minutes, but couldn't find anything on
point, and I found it difficult to rummage through everything. If
someone has written extensively about this already, please just point me
there.
My concrete example is this: I'm "spooling" documents to be printed by
sending them via FTP. There might be other ways to spool documents, such
as by sending them via e-mail, to a printer, to the screen. I would like
to represent an exception that occurs in the underlying transport
mechanism (FTP, SMTP, printing subsystem...), but of course, I don't
want my clients to know about those things directly.
In Java, I would do something like
//...
catch (FTPException wrapped) {
throw new RuntimeException("Unable to spool document", wrapped);
}
where the FTP library would throw me an FTPException to indicate that
something went wrong. I only throw a RuntimeException because I don't
necessarily want to create a custom exception class when I only report
generic, unrecoverable "I couldn't spool" exceptions. At that point,
there's nothing (yet) to gain from distinguishing exceptions by their type.
What's the corresponding exception class in Ruby to Java's generic
RuntimeException. Is it RuntimeError? StandardError? Exception? Does
anyone want to tell me I'm nuts and show me a more "standard" way of
designing exceptions in Ruby?
Thanks.
Being a Java programmer learning Ruby, I don't want my Java-based
prejudices about design pollute my thinking as I make the transition to
being a fluent Ruby speaker. Accordingly, I'd like you to suggest to me
how I should design my exception classes.
I Googled around for about 10 minutes, but couldn't find anything on
point, and I found it difficult to rummage through everything. If
someone has written extensively about this already, please just point me
there.
My concrete example is this: I'm "spooling" documents to be printed by
sending them via FTP. There might be other ways to spool documents, such
as by sending them via e-mail, to a printer, to the screen. I would like
to represent an exception that occurs in the underlying transport
mechanism (FTP, SMTP, printing subsystem...), but of course, I don't
want my clients to know about those things directly.
In Java, I would do something like
//...
catch (FTPException wrapped) {
throw new RuntimeException("Unable to spool document", wrapped);
}
where the FTP library would throw me an FTPException to indicate that
something went wrong. I only throw a RuntimeException because I don't
necessarily want to create a custom exception class when I only report
generic, unrecoverable "I couldn't spool" exceptions. At that point,
there's nothing (yet) to gain from distinguishing exceptions by their type.
What's the corresponding exception class in Ruby to Java's generic
RuntimeException. Is it RuntimeError? StandardError? Exception? Does
anyone want to tell me I'm nuts and show me a more "standard" way of
designing exceptions in Ruby?
Thanks.