Sha256: 6a1e69030ca98536cffa3195d13fd46c6756789a17fbaaefd2c45a806fe56ed2

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

# Interface to setting up a handler for any uncaught exceptions in the application.
# The block that is passed into GlobalErrorHandler.on_error will be called when
# an uncaught exception occurs.
# 
# You must be *VERY* careful when implementing your handler.  All uncaught exceptions
# will be routed to this block so any error that occur inside the block will not 
# generate exceptions.
class GlobalErrorHandler
  include Java::java::lang::Thread::UncaughtExceptionHandler
  
  # Creation point for the GlobalErrorHandler.  To use, pass in a block that takes
  # 2 parameters, the exception and the thread that the exception occured on.
  # 
  # The exception passed into this block is a *Java* Throwable, not a Ruby exception.
  # http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Throwable.html
  # 
  #   GlobalErrorHandler.on_error {|exception, thread| puts "Error #{exception} occured on thread #{thread}" }
  # 
  # or you may want to dispatch to an error handler method.
  # 
  #   GlobalErrorHandler.on_error {|exception, thread| my_error_handler_method(exception, thread) }
  def self.on_error(&callback)
    java.lang.Thread.default_uncaught_exception_handler = self.new(&callback)
  end

  def uncaughtException(thread, exception)
    @callback.call(exception, thread)
  end
  
private
  def initialize(&callback)
    @callback = callback
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
Neurogami-jimpanzee-1.0.2.1 lib/monkeybars/global_error_handler.rb
Neurogami-jimpanzee-1.0.3.2 lib/monkeybars/global_error_handler.rb
Neurogami-jimpanzee-1.0.3.4 lib/jimpanzee/global_error_handler.rb