1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
<ppdoc>
<copyright>
Copyright (c) 2001 by Addison Wesley Longman. This
material may be distributed only subject to the terms and
conditions set forth in the Open Publication License, v1.0 or
later (the latest version is presently available at
http://www.opencontent.org/openpub/).
</copyright>
<class name="Exception" super="Object" type="class">
<p/>
Descendents of class <classname>Exception</classname> are used to communicate
between <meth>raise</meth>
methods and <tt>rescue</tt> statements in <tt>begin/end</tt>
blocks. <classname>Exception</classname> objects carry information about the
exception---its type (the exception's class name), an optional
descriptive string, and optional traceback information.
<p/>
<methods type="class">
<method name="exception" ref="exception">
<callseq>
Exception.exception( <opt><obj>aString</obj></opt> )
<returns><obj>anException</obj></returns>
</callseq>
<desc>
<p/>
Creates and returns a new exception object, optionally setting the message to
<obj>aString</obj>.
<p/>
</desc>
</method>
<p/>
</methods>
<p/>
<methods type="instance">
<method name="backtrace" ref="backtrace">
<callseq>
<obj>exc</obj>.backtrace
<returns><obj>anArray</obj></returns>
</callseq>
<desc>
<p/>
Returns any backtrace associated with the exception. The
backtrace is an array of strings, each containing
either ``filename:lineNo: in `method''' or ``filename:lineNo.''
<p/>
<codefragment>
<alltt><fullcode><![CDATA[ def a
raise "boom"
end
def b
a()
end
begin
b()
rescue => detail
# print detail.backtrace.join("\n")
!- print detail.backtrace.join("\n").gsub(/-:/, 'prog.rb:')
end
]]></fullcode>
def<nbsp/>a
<nbsp/><nbsp/>raise<nbsp/>"boom"
end
<p/>
def<nbsp/>b
<nbsp/><nbsp/>a()
end
<p/>
begin
<nbsp/><nbsp/>b()
rescue<nbsp/>=><nbsp/>detail
<nbsp/><nbsp/>print<nbsp/>detail.backtrace.join("\n")
end
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
prog.rb:2:in<nbsp/>`a'
prog.rb:6:in<nbsp/>`b'
prog.rb:10
</alltt>
</codefragment>
<p/>
</desc>
</method>
<p/>
<method name="exception" ref="exception">
<callseq>
<obj>exc</obj>.exception( <opt><obj>aString</obj></opt> )
<returns><obj>anException</obj> or <obj>exc</obj></returns>
</callseq>
<desc>
<p/>
With no argument, returns the receiver. Otherwise, creates a new
exception object of the same class as the receiver, but with a
different message.
<p/>
</desc>
</method>
<p/>
<method name="message" ref="message">
<callseq>
<obj>exc</obj>.message <returns><obj>aString</obj></returns>
</callseq>
<desc>
<p/>
Returns the message associated with this exception.
<p/>
</desc>
</method>
<p/>
<method name="set_backtrace" ref="set_backtrace">
<callseq>
<obj>exc</obj>.set_backtrace( <obj>anArray</obj> )
<returns><obj>anArray</obj></returns>
</callseq>
<desc>
<p/>
Sets the backtrace information associated with <obj>exc</obj>. The
argument must be an array of <classname>String</classname> objects in the format
described in <cim><file>exception</file><front>Exception</front><back>backtrace</back><mref>backtrace</mref></cim>.
<p/>
</desc>
</method>
<p/>
</methods>
<p/>
</class>
</ppdoc>
|