From: "Jesús Gabriel y Galán" Date: 2011-09-30T05:16:08+09:00 Subject: Re: Getting Syntax error while using raise and rescue in a method On Thu, Sep 29, 2011 at 10:05 PM, Sat nosur wrote: > Hi All, > > I am relatively new to ruby programming, I am trying to capture if any > kind of exception happens in a Click method. so, I am using raise and > rescue in the "Click" method. Looks like I am doing something not > correctly and the script throws this error "syntax error, unexpected > kRESCUE rescue  Exception => e at line # 152 > >            What I am trying to do here is I am checking Id of an object > , if the id doesn't exist throw an exception, rescue an exception and > display an exception and continue executing the script > >                Could please take a look at the script ( Click method) > and help me to resolve this issue?. Advance thanks for your help > > Yours, > Sat > > Attachments: > http://www.ruby-forum.com/attachment/6640/isell_regression_script_raise_syntax_error.rb If you indent your code, you will see it more clearly: def Click(ie,id,verifyval) begin writeln 'CLICK- ' + id if id.exists? $ie.button(:id, id).click if id == 'TriggerFeedAnchor' sleep 10 elsif id == 'onestop' sleep 20 else sleep 8 end else raise Exception "ID RETURNED #{id}." rescue Exception => e puts e.message # puts $! break end end if $ie.contains_text(verifyval) puts "Test Passed. Found the string: on the page #{verifyval}. " else puts "Test Failed! Could not find the string on the page: #{verifyval} " end end After the raise, you have to close the if with an end. Rescue comes at the same scope (same indentation level) as begin. With that fixed, now you have an extra "end" after "break. You need to remove that: def Click(ie,id,verifyval) begin writeln 'CLICK- ' + id if id.exists? $ie.button(:id, id).click if id == 'TriggerFeedAnchor' sleep 10 elsif id == 'onestop' sleep 20 else sleep 8 end else raise Exception "ID RETURNED #{id}." end rescue Exception => e puts e.message # puts $! break end if $ie.contains_text(verifyval) puts "Test Passed. Found the string: on the page #{verifyval}. " else puts "Test Failed! Could not find the string on the page: #{verifyval} " end end Hope this helps, Jesus.