It’s worth noting that some people consider inheriting from Exception rather than StandardError to be bad style. Because catching Exception includes things like ScriptError::SyntaxError and SignalException::Interrupt (^C), the advice seems to be to catch StandardError instead if you don’t know what exceptions to expect and thus your custom exception classes would need to inherit from StandardError to match that.
Yep, and some common libraries (looking at you, nokogiri) don’t follow this advice and instead throw things like SyntaxError that should be limited to the Ruby parser itself.
Actually, It’s better to create a custom error that makes sense within the execution context.
Anyway, Thank you for the precision. :-)
But the purpose of my articles are just to explain how it works, not how to use it.
I believe in the fact that developers are not robots and they’ll learn all the aspects of a notion by using it, repeatedly.
Instead of telling them what’s good or not, I prefer let them figure it out by themselves.
I prefer put all of my energy on explaining the main concept and let the 5% of edge-cases on side.
It’s worth noting that some people consider inheriting from
Exceptionrather thanStandardErrorto be bad style. Because catchingExceptionincludes things likeScriptError::SyntaxErrorandSignalException::Interrupt(^C), the advice seems to be to catchStandardErrorinstead if you don’t know what exceptions to expect and thus your custom exception classes would need to inherit fromStandardErrorto match that.Yep, and some common libraries (looking at you,
nokogiri) don’t follow this advice and instead throw things likeSyntaxErrorthat should be limited to the Ruby parser itself.Actually, It’s better to create a custom error that makes sense within the execution context.
Anyway, Thank you for the precision. :-)
But the purpose of my articles are just to explain how it works, not how to use it.
I believe in the fact that developers are not robots and they’ll learn all the aspects of a notion by using it, repeatedly. Instead of telling them what’s good or not, I prefer let them figure it out by themselves.
I prefer put all of my energy on explaining the main concept and let the 5% of edge-cases on side.
But, again, thanks for your precious feedback :-)