# Doubt regarding Exception handling in Watir

**URL:** <https://www.ruby-forum.com/t/doubt-regarding-exception-handling-in-watir/187963>\
**Category:** Ruby\
**Created:** [May 3, 2010, 12:35pm UTC](https://www.ruby-forum.com/t/doubt-regarding-exception-handling-in-watir/187963 "2010-05-03T12:35:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![simbolla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@simbolla](https://www.ruby-forum.com/u/simbolla)\
**Post date:** [May 3, 2010, 12:35pm UTC](https://www.ruby-forum.com/t/doubt-regarding-exception-handling-in-watir/187963/1 "2010-05-03T12:35:02Z")

</div>

Hi all,

below is my code  
def gotourl(url)  
begin  
$ie.goto(url)  
rescue Watir::Exception::NavigationException =\> e  
puts “navigation error”  
printscreen(url)  
end  
end

1.in IE 8.0 version i get this error message when i navigate to invalid  
URL “Internet Explorer cannot display the webpage”

my doubt is why rescue part is not executing for this error.

2.i want to know is it possible to use only “Watir::Exception” in my  
rescue portion some thing this like this.

def gotourl(url)  
begin  
$ie.goto(url)  
rescue Watir::Exception =\> e  
puts “navigation error”  
printscreen(url)  
end  
end

def clickbutton()  
begin  
$ie.button(:name,‘btnGs’).flash  
rescue Watir::Exception =\> e # instead of  
Watir::Exception::UnknownObjectException  
puts “object not found error”  
printscreen($ie.title)  
end  
end

1. What is the best of Exception handling in watir?  
Please some body give me the best approach to do Exception handling  
in watir
