Did research on something like this long time ago, but it seems everyone proffers to throw the exception and let the system crash instead of handling the error internally. Some other developers I have talked to say not even to catch an exception but focus on validating the inputs and make sure we do not get garbage in... Like you said, lot of different ways to handle this kind of situation. Thank you for the video!
Still, the approach of not throwing at all and handling exceptions smoothly is also a very popular approach. As I have demonstrated in the video on exception performance cost it slows your app a lot. Also, just letting the app crash is for sure not a very good approach especially when you work with APIs and web apps in general.
@@Codewrinkles Is it possible at all, to work without exceptions? It looks for me, that (unfortunately) the DB interfaces we have cannot indicate errors in any other way then throwing an exception. I found, that catching an exception even at the DB level has a huge performance impact. If this is the case, there is no simple answer. Let's say we have a unique DB column and we want to insert a new row. The optimal would be to have an error code from DB level, without exception. But we do not have. We can try to validate the data for uniqueness before the insert and that would eliminate the probability of the exception to near to zero. Then that again hurts the performance when the data is valid (column is unique). Is the probability of receiving non-unique value to insert high? Then validating before insert and avoiding the exception is worth the effort. Does it happen rarely? Just let it be thrown.
Hi, what about caller of api, , for example in blazor if i get a problem details response from api, how should i handle those, throwing an exception in service layer of blazor or creating a service response object like you did in the video?
Did research on something like this long time ago, but it seems everyone proffers to throw the exception and let the system crash instead of handling the error internally. Some other developers I have talked to say not even to catch an exception but focus on validating the inputs and make sure we do not get garbage in... Like you said, lot of different ways to handle this kind of situation. Thank you for the video!
Still, the approach of not throwing at all and handling exceptions smoothly is also a very popular approach. As I have demonstrated in the video on exception performance cost it slows your app a lot. Also, just letting the app crash is for sure not a very good approach especially when you work with APIs and web apps in general.
@@Codewrinkles Is it possible at all, to work without exceptions? It looks for me, that (unfortunately) the DB interfaces we have cannot indicate errors in any other way then throwing an exception. I found, that catching an exception even at the DB level has a huge performance impact.
If this is the case, there is no simple answer. Let's say we have a unique DB column and we want to insert a new row. The optimal would be to have an error code from DB level, without exception. But we do not have. We can try to validate the data for uniqueness before the insert and that would eliminate the probability of the exception to near to zero. Then that again hurts the performance when the data is valid (column is unique).
Is the probability of receiving non-unique value to insert high? Then validating before insert and avoiding the exception is worth the effort. Does it happen rarely? Just let it be thrown.
Hi, what about caller of api, , for example in blazor if i get a problem details response from api, how should i handle those, throwing an exception in service layer of blazor or creating a service response object like you did in the video?
You still need to log those errors in case you want to carry out an investigation & all the details should be precise
I totally agree, of course.
Very good video. Helped me a lot.
Glad to hear it!
Thank you!
Welcome!
The object result pattern?
github url