var state = new State();
var queue = new QueueClient();
try
{
var item = await queue.DequeueAsync();
state.Item = item;
}
catch (Exception ex) when (ex is SomethingException)
{
state.Item = null;
state.Exception = ex;
}
finally
{
}
Callbacks:
public class Handler
{
public State state = new State();
public Task OnItemAsync(Item item)
{
state.Item = item;
}
public Task OnExceptionAsync(Exception ex)
{
if (ex is SomethingException)
{
state.Item = null;
state.Exception = ex;
}
}
}
var handler = new Handler();
var queue = new QueueClient();
queue.RegisterHandler(handler.OnItemAsync, handler.OnExceptionAsync);