Exception: Exception

Defined in:
lib/source/ruby.rb

Overview

Instances of Exception and its descendants are used to communicate between raise methods and rescue statements in begin/end blocks. Exception objects carry information about the exception – its type (the exception’s class name), an optional descriptive string, and optional traceback information. Applications may subclass Exception to add additional information.

Direct Known Subclasses

StandardError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg) ⇒ Exception

call-seq:

Exception.new(message = nil) -> exception

Returns a new Exception object, with an optional message.



2871
2872
2873
# File 'lib/source/ruby.rb', line 2871

def initialize(msg)
  `if(msg!=null){this._message=msg._value;}`
end

Class Method Details

.exception(arg) ⇒ Object

call-seq:

Exception.exception(arg) -> exception

Equivalent to Exception::new.



2862
2863
2864
# File 'lib/source/ruby.rb', line 2862

def self.exception(arg)
  `this.m$new(arg)`
end

Instance Method Details

#backtraceObject

call-seq:

exc.backtrace -> array

Returns any backtrace associated with the exception. The backtrace is an array of strings, each containing “/path/to/filename:line”.



2881
2882
2883
2884
2885
# File 'lib/source/ruby.rb', line 2881

def backtrace
  `if(this._stack==null){return [];}`
  `for(var i=0,lines=this._stack.match(/@[^\\n]+:\\d+/g),l=lines.length,result=[];i<l;++i){result.push($q(lines[i].match(/@\\w+:\\/*(\\/[^\\n]+:\\d+)/)[1]));}`
  return `result`
end

#exception(arg) ⇒ Object

call-seq:

exc.exception(arg) -> exception or exc

If arg is absent or equal to exc, returns the receiver. Otherwise returns a new Exception object of the same class as the receiver, but with a message equal to arg.to_str.



2894
2895
2896
2897
# File 'lib/source/ruby.rb', line 2894

def exception(arg)
  `if(arg==null||arg==this){return this;}`
  `this.m$class().m$new(arg.m$toStr())`
end

#inspectObject

call-seq:

exc.inspect -> string

Returns exc’s class name and message.



2904
2905
2906
2907
# File 'lib/source/ruby.rb', line 2904

def inspect
  `var class_name=this.m$class().__name__.replace(/\\./g,'::')`
  `this._message==''?$q(class_name):$q('#<'+class_name+': '+(this._message||class_name)+'>')`
end

#messageObject

call-seq:

exc.to_message -> string
exc.to_s       -> string
exc.to_str     -> string

Returns exc’s message (or the name of the exception class if no message is set).



2917
2918
2919
# File 'lib/source/ruby.rb', line 2917

def message
  `this._message==null?$q(this.m$class().__name__.replace(/\\./g,'::')):$q(this._message)`
end

#set_backtrace(ary) ⇒ Object

call-seq:

exc.set_backtrace(array) -> array

Sets the backtrace information associated with exc. The argument must be an array of String objects in the format described in Exception#backtrace.



2927
2928
2929
2930
2931
# File 'lib/source/ruby.rb', line 2927

def set_backtrace(ary)
  `for(var i=0,l=ary.length,result='';i<l;++i){result=result+'@xx://'+ary[i]._value+'\\n';}`
  `this._stack=result`
  return `ary`
end

#to_sObject

call-seq:

exc.to_message -> string
exc.to_s       -> string
exc.to_str     -> string

Returns exc’s message (or the name of the exception class if no message is set).



2941
2942
2943
# File 'lib/source/ruby.rb', line 2941

def to_s
  `this._message==null?$q(this.m$class().__name__.replace(/\\./g,'::')):$q(this._message)`
end

#to_strObject

call-seq:

exc.to_message -> string
exc.to_s       -> string
exc.to_str     -> string

Returns exc’s message (or the name of the exception class if no message is set).



2953
2954
2955
# File 'lib/source/ruby.rb', line 2953

def to_str
  `this._message==null?$q(this.m$class().__name__.replace(/\\./g,'::')):$q(this._message)`
end