./lib/mymodule.rb module MyModule class Error < RuntimeError; end class ConnectionError < Error; end def connect if something_failed? raise ConnectionError, "connection failed due to..." end end end
somewhere in controller
include MyModule def do_connect begin connect rescue MyModule::ConnectionError => err flash.now[:notice] => err end end