Skip to content

Conversation

@SebastianBienert
Copy link

Allow onException timer handler to catch exceptions thrown in async methods

Developing my service I came across problem which took me a while to debug. The problem is that when someone passes async lambda method to Timer onStart handler - onException handler will not be triggered. I believe it's because of the type of onStart handler wchich is Action. One solution would be to just wrap body of lambda function in additional try catch block:

Timers.Start("Poller", 10000, async () =>
{
    try
    {
        await ThrowAsyncException();
    }
    catch (Exception ex)
    {
        _logger.LogError(ex.Message);
    }
}, (err) => { _logger.LogError($"Handler: {err.Message}"); });  

But it does not feel right with a method which exposes explicit handler for this.

@PeterKottas
Copy link
Owner

Thanks! I am rly busy with other stuff right now so it's taking a while to react to these. It makes sense and I am all for improving debug experience. I kind of dislike the repetition in code this brings. Would be great if this could have been handled with one approach. I might look into this further to see if I can find a better solution, but if not, I'll be happy to merge and release this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants