# Exception handling in ruby

**URL:** <https://www.ruby-forum.com/t/exception-handling-in-ruby/65533>\
**Category:** Ruby\
**Created:** [August 18, 2006, 9:57pm UTC](https://www.ruby-forum.com/t/exception-handling-in-ruby/65533 "2006-08-18T21:57:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [August 18, 2006, 9:57pm UTC](https://www.ruby-forum.com/t/exception-handling-in-ruby/65533/1 "2006-08-18T21:57:23Z")

</div>

HI  
My exception handling routine is not able to thro the stack trace etc  
of the exception .  
for eg.  
rescue Exception  
puts $\_  
I get a nil in $\_

However when i dont handle the exception, i get the nice exception  
message  
Watir::Exception::UnknownObjectException: Unable to locate object,  
using id and

How do i capture the exception details?  
Regards

Seede

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [August 18, 2006, 10:03pm UTC](https://www.ruby-forum.com/t/exception-handling-in-ruby/65533/2 "2006-08-18T22:03:23Z")

</div>

On 8/18/06, Junkone [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Watir::Exception::UnknownObjectException: Unable to locate object,  
> using id and
> 
> How do i capture the exception details?  
> Regards
> 
> Seede

either use $! and $@, or write it more explicitly:

…  
rescue Exception ex  
puts ex.mesage  
puts ex.backtrace.join(“\n”)  
end
