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
Class Method Summary collapse
-
.exception(arg) ⇒ Object
call-seq: Exception.exception(arg) -> exception.
Instance Method Summary collapse
-
#backtrace ⇒ Object
call-seq: exc.backtrace -> array.
-
#exception(arg) ⇒ Object
call-seq: exc.exception(arg) -> exception or exc.
-
#initialize(msg) ⇒ Exception
constructor
call-seq: Exception.new(message = nil) -> exception.
-
#inspect ⇒ Object
call-seq: exc.inspect -> string.
-
#message ⇒ Object
call-seq: exc.to_message -> string exc.to_s -> string exc.to_str -> string.
-
#set_backtrace(ary) ⇒ Object
call-seq: exc.set_backtrace(array) -> array.
-
#to_s ⇒ Object
call-seq: exc.to_message -> string exc.to_s -> string exc.to_str -> string.
-
#to_str ⇒ Object
call-seq: exc.to_message -> string exc.to_s -> string exc.to_str -> string.
Constructor Details
#initialize(msg) ⇒ Exception
call-seq:
Exception.new(message = nil) -> exception
Returns a new Exception
object, with an optional message.
2897 2898 2899 |
# File 'lib/source/ruby.rb', line 2897 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
.
2888 2889 2890 |
# File 'lib/source/ruby.rb', line 2888 def self.exception(arg) `this.m$new(arg)` end |
Instance Method Details
#backtrace ⇒ Object
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”.
2907 2908 2909 2910 2911 |
# File 'lib/source/ruby.rb', line 2907 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
.
2920 2921 2922 2923 |
# File 'lib/source/ruby.rb', line 2920 def exception(arg) `if(arg==null||arg==this){return this;}` `this.m$class().m$new(arg.m$to_str())` end |
#inspect ⇒ Object
call-seq:
exc.inspect -> string
Returns exc’s class name and message.
2930 2931 2932 2933 |
# File 'lib/source/ruby.rb', line 2930 def inspect `var class_name=this.m$class().__name__.replace(/\\./g,'::')` `this.__message__==''?$q(class_name):$q('#<'+class_name+': '+(this.__message__||class_name)+'>')` end |
#message ⇒ Object
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).
2943 2944 2945 |
# File 'lib/source/ruby.rb', line 2943 def `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
.
2953 2954 2955 2956 2957 |
# File 'lib/source/ruby.rb', line 2953 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_s ⇒ Object
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).
2967 2968 2969 |
# File 'lib/source/ruby.rb', line 2967 def to_s `this.__message__==null?$q(this.m$class().__name__.replace(/\\./g,'::')):$q(this.__message__)` end |
#to_str ⇒ Object
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).
2979 2980 2981 |
# File 'lib/source/ruby.rb', line 2979 def to_str `this.__message__==null?$q(this.m$class().__name__.replace(/\\./g,'::')):$q(this.__message__)` end |