How to Handle Unhandled exception

Best practices, code snippets for common functionality, examples, and guidelines.
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to Handle Unhandled exception

Post by krstcs » Mon Jan 08, 2018 7:56 pm

If that is the case, then you should not be using the popup watcher at all. If you want the test to fail when that specific unhandled exception happens, then don't handle it and if your System Under Tests (SUT) can't continue then Ranorex will fail because it won't be able to continue executing the test with the exception in place.

The popup watcher should only be used to handle popups where the system/test should not fail, but needs to handle the popup in some way to allow the test to continue WITHOUT failure. The popup watcher is not designed for effective use as a test error handler.

If your test should fail due to a popup, then you should code the test so that it can't continue if the popup is there, using a Validate.NotExists(<Popup>) or something similar, or just letting Ranorex fail when trying to find/act on the next element.

In addition, the popup watcher runs in a separate thread than the test itself, and therefore will not be able to stop the test on a failure. The best you can do is create your callback method in such a way that it passes failure to the report via a Report.Failure() call. You will need to code your own callback for this though.
Shortcuts usually aren't...

Posts: 42
Joined: Tue Dec 20, 2016 10:16 pm

Re: How to Handle Unhandled exception

Post by armstronghm24 » Mon Jan 08, 2018 8:06 pm

I am not sure I agree with the first part. It seems like the popup watcher was built for failures since they are for unexpected popups or am I not understanding something correctly? The reason I want to use the popup watcher is so that testing will continue if an unexpected popup error occurs, however I want to make sure the report still captures the failure. At least in my case, unexpected popups prevent any further testing since the normally functioning parts of the UI are disabled unless the popup is dismissed.

User avatar
Ranorex Guru
Ranorex Guru
Posts: 7465
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to Handle Unhandled exception

Post by odklizec » Mon Jan 08, 2018 9:02 pm

There is already a user voice regarding the ability to pause/stop main test thread from popupwatcher thread: ... from-popup
You can vote for it, but it already appears to be under review.

BTW check this post about killing test from popup watcher: ... tml#p46702
Last edited by odklizec on Mon Jan 08, 2018 10:01 pm, edited 1 time in total.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to Handle Unhandled exception

Post by krstcs » Mon Jan 08, 2018 9:41 pm

As I said, if you want the test to fail, then you should code the test specifically for that. The popup watcher is there to handle things that should not normally impact (read fail) the test.

Once you have a failure in a test, you can really no longer trust the rest of the test. There is no way you can handle every possible situation that can result due to the failure, especially if it is an exception in the SUT.

You do whatever you think is right, but for me, a failure should stop the test. This is one reason that tests should be short and to-the-point. That way a failure only impacts that test and not others. However, in very complex SUTs that may not be possible. My question is, how do your users react to these failures? Do they have to start over? Is the system still stable, etc.? Just some things to think about.

Good luck!
Shortcuts usually aren't...

Posts: 254
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: How to Handle Unhandled exception

Post by Vaughan.Douglas » Tue Jan 09, 2018 2:46 pm

I think the main reason you'd want to use this approach was to make sure you captured the exception details and allow for a clean exit from the test. If you don't handle it in this way, Ranorex will probably fail on some element error (not found, can't click, whatever) which doesn't tell you much about what really caused the exception. The popup watcher should trigger closer to the error event making it easier to backtrack.
Doug Vaughan