What is a conventional place to keep custom Exception definitions in a rails project? [closed] What is a conventional place to keep custom Exception definitions in a rails project? [closed] ruby-on-rails ruby-on-rails

What is a conventional place to keep custom Exception definitions in a rails project? [closed]


I would probably go with lib/exceptions/thing_exploded.rb to keep each class in a separate file.


Unless your exceptions are so severe they shouldn't be rescued from, subclassing them from Exception isn't appropriate.

Exceptions such as fatal and NoMemoryError are subclasses of Exception, so if you had code such as rescue Exception to handle ThingExploded and ThingIsMissing, you'd be rescuing all kinds of stuff that are best left alone.

It's better to subclass them from StandardError instead.


I'm going with app/models/model_name/exceptions.rb, keeping them inside the module.