def exception_log
      return unless logfile

      require 'logger'

      l_file = Logger.new(logfile)

      # the code below finds the last exception
      e = nil

      ObjectSpace.each_object do |o|
        if ::Exception === o
          e = o
        end
      end

      l_file.info '*** below you find the most recent exception thrown, this will be likely (but not certainly) the exception that made the application exit abnormally ***'
      l_file.error e

      l_file.info '*** below you find all exception objects found in memory, some of them may have been thrown in your application, others may just be in memory because they are standard exceptions ***'

      # this code logs every exception found in memory
      ObjectSpace.each_object do |o|
        if ::Exception === o
          l_file.error o
        end
      end

      l_file.close
    end
def exception_log
      return unless logfile

      require 'logger'

      l_file = Logger.new(logfile)

      # the code below finds the last exception
      e = nil

      ObjectSpace.each_object do |o|
        if ::Exception === o
          e = o
        end
      end

      l_file.info '*** below you find the most recent exception thrown, this will be likely (but not certainly) the exception that made the application exit abnormally ***'
      l_file.error e

      l_file.info '*** below you find all exception objects found in memory, some of them may have been thrown in your application, others may just be in memory because they are standard exceptions ***'

      # this code logs every exception found in memory
      ObjectSpace.each_object do |o|
        if ::Exception === o
          l_file.error o
        end
      end

      l_file.close
    end
This is a nice little function for debugging purposes:
 In case a multi-threaded ruby script exits due to an uncaught exception
 it may be difficult to find out where the exception came from because
 one cannot catch exceptions that are thrown in threads other than the main
 thread.

 This function searches for all exceptions in memory and outputs them to $stderr
 (if it is connected) and to a log file in the pid-file directory.