# File lib/ruote/error_handler.rb, line 73
    def handle (msg, fexp, exception)

      wfid = msg['wfid'] || (msg['fei']['wfid'] rescue nil)
      fei = msg['fei'] || (fexp.h.fei rescue nil)

      backtrace = exception.backtrace || []

      # debug only

      if $DEBUG || ARGV.include?('-d')

        puts "\n== worker intercepted error =="
        puts
        p exception
        puts backtrace[0, 20].join("\n")
        puts "..."
        puts
        puts "-- msg --"
        msg.keys.sort.each { |k|
          puts "    #{k.inspect} =>\n#{msg[k].inspect}"
        }
        puts "-- . --"
        puts
      end

      # on_error ?

      return if fexp && fexp.handle_on_error(msg, exception)

      # emit 'msg'

      @context.storage.put_msg(
        'error_intercepted',
        'error_class' => exception.class.name,
        'error_message' => exception.message,
        'error_backtrace' => exception.backtrace,
        # for backward compatibility
        'message' => exception.inspect,
        'wfid' => wfid,
        'msg' => msg)

      # fill error in the error journal

      @context.storage.put(
        'type' => 'errors',
        '_id' => "err_#{Ruote.to_storage_id(fei)}",
        'message' => exception.inspect,
        'trace' => backtrace.join("\n"),
        'fei' => fei,
        'msg' => msg
      ) if fei
    end