# Exception Handling in SimpleAuthentificator

**URL:** <https://community.hivemq.com/t/exception-handling-in-simpleauthentificator/1321>\
**Category:** HiveMQ Extension SDK\
**Created:** [July 25, 2022, 3:17pm UTC](https://community.hivemq.com/t/exception-handling-in-simpleauthentificator/1321 "2022-07-25T15:17:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![juggie](https://avatars.discourse-cdn.com/v4/letter/j/c57346/32.png) [@juggie](https://community.hivemq.com/u/juggie)\
**Post date:** [July 25, 2022, 3:17pm UTC](https://community.hivemq.com/t/exception-handling-in-simpleauthentificator/1321/1 "2022-07-25T15:17:10Z")

</div>

Hi,

can anyone explan how is exception handling done in SimpleAuthetificator?

My problem:  
I have an extension with a SimpleAuthentificator, which authenticates the certificates in the onConnect() method, this extension has the highest priority.

An other extension has a ClientLifecycleEventListener, which listen to the event onAuthenticationSuccessful() and do some stuff…

What happens in the listener, if an exception occurs in the authenticator, for example a RuntimeException? Is there a way to respond to that?

Has connection to

> [@Does ClientLifecycleEventListener block other extensions](https://community.hivemq.com/t/does-clientlifecycleeventlistener-block-other-extensions/1320):
>
> Hi! Does the an event Listener, which implements the ClientLifecycleEventListener block processing or does it run asynchronously? My problem: I have an extension with a SimpleAuthentificator, which authenticates the certificates in the onConnect() method, this extension has the highest priority. Then a second extension with an Authorizer, which implements PublishInboundInterceptor and SubscriptionAuthorizer, which prohibits/allows subscribing to a topic. A third extension is to implement an …

---

<div class="post-metadata">

**Author:** ![FloLi](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/floli/32/17_2.png) [@FloLi](https://community.hivemq.com/u/FloLi)\
**Post date:** [August 1, 2022, 7:53am UTC](https://community.hivemq.com/t/exception-handling-in-simpleauthentificator/1321/2 "2022-08-01T07:53:22Z")

</div>

Hi juggie,

if the `onConnect()` method of the `SimpleAuthenticator` throws an exception that is not handled by the custom code then the authentication fails for the client and `onAuthenticationSuccessful()` of the `ClientLifecycleEventListener` will never be called.

Instead you can override `onDisconnect` or more specific `onAuthenticationFailedDisconnect()` in the listener to react to it.

But it is recommended that you handle exceptions and call `failAuthentication()` on the output of the `Authenticator`

P.S. priority is only important if you have multiple extensions that implements the same interfaces. E.g. multiple extensions that have an `Authenticator`. Then these will be called by priority.

Regards  
Flo
