menu

arrow_back How to track Exception in all methods?

by
2 votes
There is a device that returns an error and then needs to be re-initialized, the error can occur in different methods, but the error id is the same. How can I handle exception globally so I don't have to write it in catch in each method?

1 comment

I would make a wrapper over this device in which exceptions are caught and handled correctly.
Still, logic on exceptions is not very good.
And global exception handling in business logic is even worse.

2 Answers

by
0 votes
I would suggest something like TryGet pattern
https://stackoverflow.com/questions/37546622/best-...

The other option is a global catcher, catching not only the exception, but also through reflection the method that was called.

Or a wrapper that takes a lambda and repeats it several times on exceptions
by
1 vote