How can I catch browser error in watir-webdriver?

Like I want to catch two errors saparately:

  1. when somebody closes the browser intentionally. Or it is closed by
    some error, I mean any browser related error.

ajay paswan wrote in post #1078471:

Like I want to catch two errors saparately:

  1. when somebody closes the browser intentionally. Or it is closed by
    some error, I mean any browser related error.

Please help me somebody. I am stuck here.

On 5 Oct 2012, at 02:15, ajay paswan [email protected] wrote:

ajay paswan wrote in post #1078471:

Like I want to catch two errors saparately:

  1. when somebody closes the browser intentionally. Or it is closed by
    some error, I mean any browser related error.

Please help me somebody. I am stuck here.

What have you tried so far?

Use something along these lines to record the types of error and
simulate them. Once you have the exact error reported, like “end of file
reached”, you can rescue that error by using rescue like a case
statement: http://rubylearning.com/satishtalim/ruby_exceptions.html


require ‘watir-webdriver’

begin

b = Watir::Browser.new
10.times {
b.goto “www.google.com
sleep 5
#Close or disconnect the browser here
#and see what error message you get
b.goto “about:blank”
}

rescue
puts “Your error message was: #{$!}”
exit
ensure
b.close rescue nil
end