[Wtr-general] How to capture exception details
Nathan Christie
forum-watir-users at openqa.org
Thu Dec 21 14:15:55 EST 2006
You start with a begin block, placing the code you know may throw an exception. The rescue block lets you work with the exception gracefully. There are some Ruby system globals that are useful to know here for reporting purposes. The ensure block will execute code regardless of whether an exception occurred.
$! - The exception information message set by 'raise'.
$@ - Array of backtrace of the last exception thrown.
$stderr - The current standard error output.
begin
myObject = Object.new( param )
myObject.action1( param )
...
rescue => e
puts "Exception occured:
puts $@
ensure
myObject.tearDown()
end
Hope this helps,
—›Nathan Christie
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=5886&messageID=16494#16494
More information about the Wtr-general
mailing list