Exception Handling inside a function

I’m trying to create an exception handling within a function. But whenever I do that , I get a compile error saying that my browser instance cannot be recognized which I had created before the exception but within the function.

Here is my code:

This code works fine when I remove the exception.

Can someone give me a solution for this?
Thank you!

You can make a work around :wink:

Put the exception handling inside the function and return the Browser variable. Then everything works.


@Code4FunVienna, very nice! Thank you!

This is a great solution but it’ll work only when I have like 2 action statements inside the function (In the above eg: launch chrome and populate text field)
I wanted to write multiple exceptions within my function.
Consider the following code:

Here I want to give exceptions for launch chrome, populate text field and so on. If i try applying your solution here then I’ll have to create different functions for each actions which will become very complex. Is there a better alternative?
[PS: The entire switch case in inside a function]
Thank you!

Hi @Yash_bitla99
a bit late but I found that if I use not the default name that is returned then exception handling works.