You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a question about the behaviour of catching exceptions, specifically the exception thrown when trying to access a parameter that doesn't exist. The exception thrown is Main::Parameter::NoneSuch, and the exception message is the string representation of the key used with the params object. This is fine, except for the fact that Main catches the exception and simply prints out the exception message, which doesn't have any context associated with it.
Reading that back, it may be a little hard to understand what I mean. So here's an example:
Main{defrun# Try to access non-existent paramparams[:nothing]end}
The output of this:
$ ruby example.rb
nothing
If you're not used to working with Main you could end up tearing you hair out, trying to work out why your program has stopped running and it's now spitting out a single word (this may or may not have happened to me).
I would propose either re-raising the exception (it certainly is exceptional behaviour, and it should only ever happen in development) or at least printing the exception class name, e.g. Main::Parameter::NoneSuch => nothing. Or perhaps catch that exception specifically and print out a helpful message.
I'm happy to fork and code a possible solution if you would be willing to look over it?
Thanks
The text was updated successfully, but these errors were encountered:
Hi,
Thanks for an excellent tool.
I have a question about the behaviour of catching exceptions, specifically the exception thrown when trying to access a parameter that doesn't exist. The exception thrown is
Main::Parameter::NoneSuch
, and the exception message is the string representation of the key used with theparams
object. This is fine, except for the fact that Main catches the exception and simply prints out the exception message, which doesn't have any context associated with it.Reading that back, it may be a little hard to understand what I mean. So here's an example:
The output of this:
If you're not used to working with Main you could end up tearing you hair out, trying to work out why your program has stopped running and it's now spitting out a single word (this may or may not have happened to me).
I would propose either re-raising the exception (it certainly is exceptional behaviour, and it should only ever happen in development) or at least printing the exception class name, e.g.
Main::Parameter::NoneSuch => nothing
. Or perhaps catch that exception specifically and print out a helpful message.I'm happy to fork and code a possible solution if you would be willing to look over it?
Thanks
The text was updated successfully, but these errors were encountered: