« Back to Index

Ruby Fail vs Raise

View original Gist on GitHub

Ruby Fail vs Raise.md

Raise

Use raise instead of fail to rethrow exceptions

This means if you catch an error that’s been thrown by an external gem/library then you can choose to re-throw it as a different exception (i.e. your own Exception error, named specifically relevant to your application)

Fail

Use fail instead of raise to signal exceptions

This means if you catch an error that’s been thrown by your own code (e.g. you’ve raised a custom error/exception), then this means you don’t intend to re-throw the exception as something else, you’ll instead deal with that exact exception now