# Open TAP 9.18.5 removes the result listener when there's any unhandled exception in result listener

**URL:** https://forum.opentap.io/t/open-tap-9-18-5-removes-the-result-listener-when-theres-any-unhandled-exception-in-result-listener/883
**Category:** Technical
**Tags:** plugin
**Created:** [October 6, 2022, 7:14am UTC](https://forum.opentap.io/t/open-tap-9-18-5-removes-the-result-listener-when-theres-any-unhandled-exception-in-result-listener/883 "2022-10-06T07:14:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![gubendiren](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@gubendiren](https://forum.opentap.io/u/gubendiren)
#### Post date: [October 6, 2022, 7:14am UTC](https://forum.opentap.io/t/open-tap-9-18-5-removes-the-result-listener-when-theres-any-unhandled-exception-in-result-listener/883/1 "2022-10-06T07:14:11Z")

</div>

Hi,

Currently, we are upgrading our OpenTap from 9.10.0 to 9.18.5. After our upgrade, we found a difference in behavior.

In 9.18.5, when an unhandled exception is thrown from the custom result listeners override methods, test execution removes the result listener, but in 9.10.0, it’s different. The result listener will not be removed and will continue to listen till the test execution ends.

I just wanted to know, is there any way I can prevent the result listener from being removed when there’s an unhandled exception?

Thanks in advance for your help

Regards,  
Gubendiren. R

---

<div class="post-metadata">

### Author: ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)
#### Post date: [October 6, 2022, 7:36am UTC](https://forum.opentap.io/t/open-tap-9-18-5-removes-the-result-listener-when-theres-any-unhandled-exception-in-result-listener/883/2 "2022-10-06T07:36:04Z")

</div>

The right way would be to fix the first result listener so that it does not throw exceptions. If that is not possible, you can create a new class that inherits from the first one but wraps the method calls in try/catch.

````cs
class ResultListener2 : ResultListener1{
     public override void OnTestStepRunStart(TestStepRun stepRun)
     {
         try
         {
              base.OnTestStepRunStart(stepRun);
          }
          catch
          {
           // handle exception?
          }
     }
}```

Then you can use this second class instead of the first one.
````

---

<div class="post-metadata">

### Author: ![gubendiren](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@gubendiren](https://forum.opentap.io/u/gubendiren)
#### Post date: [October 6, 2022, 8:04am UTC](https://forum.opentap.io/t/open-tap-9-18-5-removes-the-result-listener-when-theres-any-unhandled-exception-in-result-listener/883/3 "2022-10-06T08:04:22Z")

</div>

Thanks for the prompt support.

This would solve the problem of the result listener being removed, but this creates another problem.

We use this result listener to store the test results for regulatory purposes so, it’s not useful to continue the test execution without being able to store the results.

Is there any way I can stop the test execution and set the verdict to error when there’s any exception in the result listener?

---

<div class="post-metadata">

### Author: ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)
#### Post date: [October 6, 2022, 8:50am UTC](https://forum.opentap.io/t/open-tap-9-18-5-removes-the-result-listener-when-theres-any-unhandled-exception-in-result-listener/883/4 "2022-10-06T08:50:45Z")

</div>

Yes, in this case you can call `TestPlanRun.MainThread.Abort()`.

I am not sure the verdict will be Error though, it might be set to Aborted.

---

<div class="post-metadata">

### Author: ![gubendiren](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@gubendiren](https://forum.opentap.io/u/gubendiren)
#### Post date: [October 6, 2022, 12:59pm UTC](https://forum.opentap.io/t/open-tap-9-18-5-removes-the-result-listener-when-theres-any-unhandled-exception-in-result-listener/883/5 "2022-10-06T12:59:44Z")

</div>

Sorry correct me if I’m wrong. I think The result listener dont have access to TestPlanRun.MainThread to call abort.

---

<div class="post-metadata">

### Author: ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)
#### Post date: [October 6, 2022, 1:03pm UTC](https://forum.opentap.io/t/open-tap-9-18-5-removes-the-result-listener-when-theres-any-unhandled-exception-in-result-listener/883/6 "2022-10-06T13:03:04Z")

</div>

They should have. Depends a bit on the OpenTAP version maybe.

MainThread is a public property of TestPlanRun.
