The use of exceptions in C# is basically okay, but you should be careful not to use too many exceptions. If exceptions are constantly used for all...
For further actions, you may consider blocking this person and/or reporting abuse
I understand it's an example but I am not sure why the code below needs to be an exception
Hey!
We hereby create our own error object which we want to manage ourselves. We do not use the exception handling of dotnet here, as this can be very "expensive". This is about known errors that can occur. It is not about unexpected errors
Hi! There's a nugget package called ErrorOr that's implementing this pattern. Search it at GitHub
Hi, I use the Ardalis.Result package and result succesful for web apis.
Overall a neat idea for Error flow design. Leave the try catch block for unexpected exception scenario.
Hope there is also a design pattern to convince your fellow engineers to use this pattern instead of throwing try catch exception everywhere then use finally block as flow control to further throw more exceptions.....
I just have one question, if you have your own error object and you know exactly where the error occurs, why do you need the call stack? It needs a lot of power which is not needed here!
Hi Ben,
Thanks for the question, its for debugging reusable workflow.
Let's say we are executing : A -> B -> C -> D and another A -> Z -> L -> D. If error happened at D and we are evaluating the error at A, I would like to know the exact path it went through instead of just result code and message.
Makes no sense, as you know exactly which one occurred, even where it occurred. You don't need the stack, in this case it's pure overhead!
Yeah on second thought, you probably don't need the exception stack if the error classes and error flows were well defined.
The code I was working doesnt have well defined exceptions and rethrow a different generic Exception everytime it entered catch block. It's hard to traceback to the original location so maybe unconsciously I thought of using a combined stacktrace to tackle this issue. 🤔 Does this make better sense?
This example is about implementing an error structure, as error handling under .Net is good but unfortunately very resource-intensive.
If your project relies on the .Net standard, this is not wrong, but it can cost performance.
If you get error messages that come from code where you don't know where it occurs, the stack is essential.