Error handling strategies in ASP.Net Core APIs

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ย. 2024

ความคิดเห็น • 14

  • @victormoreno2767
    @victormoreno2767 ปีที่แล้ว

    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!

    • @Codewrinkles
      @Codewrinkles  ปีที่แล้ว +1

      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.

    • @williamforsyth6667
      @williamforsyth6667 ปีที่แล้ว

      @@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.

  • @alfonsdeda8912
    @alfonsdeda8912 7 หลายเดือนก่อน

    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?

  • @marshallnyamadzawo8553
    @marshallnyamadzawo8553 ปีที่แล้ว

    You still need to log those errors in case you want to carry out an investigation & all the details should be precise

    • @Codewrinkles
      @Codewrinkles  ปีที่แล้ว

      I totally agree, of course.

  • @danielcostache6980
    @danielcostache6980 ปีที่แล้ว

    Very good video. Helped me a lot.

  • @3rd_Century
    @3rd_Century ปีที่แล้ว

    Thank you!

  • @fadidib8516
    @fadidib8516 ปีที่แล้ว

    The object result pattern?

  • @jayakumar2927
    @jayakumar2927 9 หลายเดือนก่อน

    github url