Attach Browser check if output is nothing

Hi Experts

I have a process where Internet Explorer is opened and the window is attached by using the Attach Browser activity. The variable is used in an Invoke Method to bring the browser window to the foreground (browser.Element BringToForeground).

However if the webpage returns an error in an pop-up message (e.g. error in credentials) the process will fail as the window cannot be attached (I assume). I then get the following error:

Raw Message: Object
Message: "VisualBasicValue: Object reference not set to an instance of an object.

I believe that this is due to the browser object never being set - is there a way to check if the UIBrowser Output of the Attach Browser activity is nothing or null?

Use condition in the if activity → browserobjectvariable is Nothing

Else use try/catch block for the browser attach.
If error is thrown, then the browser object is nothing and decide what to do in the catch block like ignoring error or message box etc.,