Stack traces: Difference between revisions

Content deleted Content added
Added Oz.
Line 360: Line 360:
Fatal error: exception Division_by_zero
Fatal error: exception Division_by_zero
Raised at file "test.ml", line 4, characters 10-17
Raised at file "test.ml", line 4, characters 10-17

=={{header|Oz}}==
System exceptions contain the current stack at the nested feature <code>debug.stack</code>. For example:
<lang oz>declare
proc {Test}
_ = 1 div 0
end
in
try
{Test}
catch E then
{Inspect E}
end</lang>
Output:
[[File:Oz_stacktrace1.png|center|Stack trace of a system exception in Oz.]]

To have such a stack trace in custom exceptions, either indicate this by throwing a record value with a <code>debug:unit</code> feature or use the [http://www.mozart-oz.org/documentation/base/exception.html Exception] module to create exceptions.

To access the stack trace directly, you can use the undocumented internal Debug module. Its <code>getTaskStack</code> function takes a thread, a depth value and a boolean "verbose" flag. It returns a list of stack frames. Example:
<lang oz>%% make sure that simple function calls are not optimized away
\switch +controlflowinfo

declare
[Debug] = {Link ['x-oz://boot/Debug']}

proc {F} {G} end

proc {G} {H} end

proc {H}
{Inspect {Debug.getTaskStack {Thread.this} 100 true}}
end
in
{F}</lang>

Output:
[[File:Oz_stacktrace2.png|center|Stack trace created by the Debug module.]]


=={{header|Perl}}==
=={{header|Perl}}==