I have noticed that in the Ruby exception hierarchy, there are "errors" such as ArgumentError and there are "exceptions" such as SignalException. Is there a certain practise of naming exceptions? thanks in advance, ell.
2 Answers
Looking at the list of Ruby exceptions, SignalException
is the only one that is named *Exception
; everything else is an XXXError
(except for SystemExit
and fatal
). If anything, the practice is to name your exception FooError
. I'm having trouble finding any specific reason why SignalException
isn't named SignalError
.
-
2I would second that. Another question, since everything we should be rescuing is inherited from
StandardError
, would it make sense to userescue StandardError => error
instead ofrescue StandardError => exception
? I've always usedexception
but this answer gave me pause now. Commented Jan 6, 2019 at 23:16 -
The convention is Module::#{Type}Error
for anything caused by your application (e.g. http://weblog.jamisbuck.org/2007/3/7/raising-the-right-exception). Exception handling in Ruby isn't stratified the same way as in Java since the exception model is different at the language level.
From what I've seen, the conventions are adhered to a little more loosely for C/FFI/JNA extensions.
Error
in their names.