Provides a wrapper for running code inside a 'safety net' Any exceptions raised inside a safety net is handled and reported via loggers, email or Hoptoad.
The safety net can be configured via DaemonKit.config.safety, which holds the only instance of the safety net.
# File lib/daemon_kit/safety.rb, line 23 def instance @instance ||= new end
# File lib/daemon_kit/safety.rb, line 33 def register_error_handler( klass ) name = klass.to_s.split('::').last.downcase DaemonKit.logger.debug( "Registering error handler '#{name}' (#{klass})" ) if DaemonKit.logger instance.instance_eval( def #{name} @#{name} ||= #{klass}.instance end, __FILE__, __LINE__ ) end
# File lib/daemon_kit/safety.rb, line 59 def get_handler if @handler && self.respond_to?( @handler ) h = send( @handler ) return h if h.class.ancestors.include?( DaemonKit::ErrorHandlers::Base ) end return nil end
Run the provided block inside a safety net.
# File lib/daemon_kit/safety.rb, line 47 def run(&block) begin block.call rescue => e # Log DaemonKit.logger.fatal "Safety net caught exception: #{e.message}" DaemonKit.logger.fatal "Backtrace: #{e.backtrace.join("\n ")}" get_handler.handle_exception( e ) if get_handler end end
Generated with the Darkfish Rdoc Generator 2.