Sha256: 792cae452474a4d363594cd24e579ef092c383b7a62ac2d925772ecea184a856

Contents?: true

Size: 1.72 KB

Versions: 64

Compression:

Stored size: 1.72 KB

Contents

# encoding: ascii-8bit

# Copyright 2014 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt

# COSMOS specific additions to the Ruby Exception class
class Exception
  # @param hide_runtime_error_class [Boolean] Whether to hide the Exception
  #   error class if the class is RuntimeError. Other classes will continue to
  #   be printed.
  # @param include_backtrace [Boolean] Whether to include the full exception
  #   backtrace
  # @return [String] The formatted Exception
  def formatted(hide_runtime_error_class = false, include_backtrace = true)
    if include_backtrace and self.backtrace
      if hide_runtime_error_class and self.class == RuntimeError
        "#{self.message}\n#{self.backtrace.join("\n")}"
      else
        "#{self.class.to_s.split('::')[-1]} : #{self.message}\n#{self.backtrace.join("\n")}"
      end
    else
      if hide_runtime_error_class and self.class == RuntimeError
        "#{self.message}"
      else
        "#{self.class.to_s.split('::')[-1]} : #{self.message}"
      end
    end
  end

  # @return [Array(String, Fixnum)] The filename and line number where the Exception
  #   occurred
  def source
    trace = self.backtrace[0]
    split_trace = trace.split(':')
    filename = ''
    line_number = ''
    if trace[1..1] == ':' # Windows Path
      filename = split_trace[0] + ':' + split_trace[1]
      line_number = split_trace[2].to_i
    else
      filename = split_trace[0]
      line_number = split_trace[1].to_i
    end

    [filename, line_number]
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
cosmos-4.5.2-java lib/cosmos/core_ext/exception.rb
cosmos-4.5.2 lib/cosmos/core_ext/exception.rb
cosmos-4.5.1-java lib/cosmos/core_ext/exception.rb
cosmos-4.5.1 lib/cosmos/core_ext/exception.rb
cosmos-4.5.0-java lib/cosmos/core_ext/exception.rb
cosmos-4.5.0 lib/cosmos/core_ext/exception.rb
cosmos-4.4.2-java lib/cosmos/core_ext/exception.rb
cosmos-4.4.2 lib/cosmos/core_ext/exception.rb
cosmos-4.4.1-java lib/cosmos/core_ext/exception.rb
cosmos-4.4.1 lib/cosmos/core_ext/exception.rb
cosmos-4.4.0-java lib/cosmos/core_ext/exception.rb
cosmos-4.4.0 lib/cosmos/core_ext/exception.rb
cosmos-4.3.0-java lib/cosmos/core_ext/exception.rb
cosmos-4.3.0 lib/cosmos/core_ext/exception.rb
cosmos-4.2.4-java lib/cosmos/core_ext/exception.rb
cosmos-4.2.4 lib/cosmos/core_ext/exception.rb
cosmos-4.2.3-java lib/cosmos/core_ext/exception.rb
cosmos-4.2.3 lib/cosmos/core_ext/exception.rb
cosmos-4.2.2-java lib/cosmos/core_ext/exception.rb
cosmos-4.2.2 lib/cosmos/core_ext/exception.rb