require 'cabar'

module Cabar

  # Common error base class for Cabar.
  class Error < ::Exception

    # Format a Error in cabar YAML format.
    def self.cabar_format err
      msg = [ ]
      msg << Cabar.yaml_header(:error)
      msg << "    message: #{err.inspect.inspect}"
      msg << "    backtrace: "
      if err.respond_to? :backtrace
        err.backtrace.each do | x |
          msg << "    - #{x.to_s.inspect}"
        end
      end
      msg << ''
      msg.join("\n")
    end

    def self.cabar_error_handler &blk
      yield
    rescue SystemExit => err
      raise err
    rescue Exception => err
      $stderr.puts Cabar::Error.cabar_format(err)
      Kernel.exit 10
    end

  end # class

end # module



require 'cabar'

module Cabar

  # Common error base class for Cabar.
  class Error < ::Exception

    # Format a Error in cabar YAML format.
    def self.cabar_format err
      msg = [ ]
      msg << Cabar.yaml_header(:error)
      msg << "    message: #{err.inspect.inspect}"
      if err.respond_to? :backtrace
        msg << "    backtrace: "
        err.backtrace.each do | x |
          msg << "    - #{x.to_s.inspect}"
        end
      end
      msg << ''
      msg.join("\n")
    end

    def self.cabar_error_handler &blk
      yield
    rescue SystemExit => err
      raise err
    rescue Exception => err
      $stderr.puts Cabar::Error.cabar_format(err)
      Kernel.exit 10
    end

  end # class

end # module



Print backtrace: only if err responds to it.
Print backtrace: only if err responds to it.

git-svn-id: 55dab261027a0615fa60e6fe1b42a29d056462f7@84 3b289f47-807e-410a-85af-7ee1d5ead6e2
