1

In the following code i want to handle the exception.if msg[0] not found i have to catch that exception message msg[2] in rescue and if it is found put the success message msg[1]

puts "Verifying Home Page"
 def verifyHomepage(*args)
 begin
  args.each do |msg|    
    page.find(msg[0])
    puts msg[1]
    rescue
    puts msg[2]      
  end
end
end
verifyHomepage(['#logoAnchorr', 'logo anchor found', 'Logo anchor not Found'], ['.navbar-inner', 'Header Bar found', 'Header Bar  not Found'])

In the above code iam getting error sysntax error unexpected keyword rescue expecting keyword end

1
  • Is it because the rescue is inside the args.each block? Commented May 16, 2013 at 5:12

2 Answers 2

2

Salil has pointed you where to fix,that's correct. Now The below approach also you could adapt:

puts "Verifying Home Page"

def verifyHomepage(*args)
  args.each do |msg|   
    next puts(msg[1]) if page.find(msg[0]) rescue nil  
    puts msg[2]     
  end
end
a = [['#logoAnchorr', 'logo anchor found', 'Logo anchor not Found'], ['.navbar-inner', 'Header Bar found', 'Header Bar  not Found']]
verifyHomepage(*a)

Output:

Verifying Home Page
Logo anchor not Found
Header Bar  not Found
Sign up to request clarification or add additional context in comments.

Comments

1

You have to write begin inside the block

puts "Verifying Home Page"
def verifyHomepage(*args)  
    args.each do |msg|
      begin
        page.find(msg[0])
        puts msg[1]
      rescue
        puts msg[2]
    end
  end
end
verifyHomepage(['#logoAnchorr', 'logo anchor found', 'Logo anchor not Found'], ['.navbar-inner', 'Header Bar found', 'Header Bar  not Found'])

2 Comments

Is it a good idea to have an end after the rescue statement, at all?
Yes i agree with you @summea

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.