Coding Shorts: ASP.NET 8 - New Exception handling

Поділитися
Вставка
  • Опубліковано 6 лип 2024
  • I am excite to have a more standard approach to global exception handling in .NET 8. But the legacy of the API does cause an issue. Let me show you how it works!
    You can hire me too! You can reach me at my new website:
    - shawn.wildermuth.com
    00:00 Introduction
    01:12 Creating the Project
    02:01 Throwing an Exception
    03:25 Creating the Exception Handler
    05:47 Testing the Handler
    06:54 Working Around Empty Constructor
    09:12 Watching Instead of Handling the Exception
    If you like this video, you might like other videos in my Instructional Videos:
    - • Instructional Videos
  • Наука та технологія

КОМЕНТАРІ • 67

  • @godfathermikal
    @godfathermikal 7 місяців тому +1

    Can't wait to upgrade. I have a need for this right now. 👏 Thank you, sir!

  • @lyudmilpetrov79
    @lyudmilpetrov79 Місяць тому

    Thank you so much for your teaching great and simple presentation God bless you

  • @Phonophobic
    @Phonophobic 7 місяців тому

    Thanks so much for this. I liked/subscribed and did all the things. You’re doing great work, man.

  • @Rhysling2
    @Rhysling2 7 місяців тому

    Did not know about this. Thank you Shawn.

  • @mouradaissani8957
    @mouradaissani8957 7 місяців тому

    Thank you Shawn

  • @larrye
    @larrye 7 місяців тому

    Looks like a good step forward. I've always wanted the try/catch syntax to be stream-lined.
    Maybe create a Base class (or decorator) that could handle process/handle most exceptions that would allow a lot of boilerplate exception handling to be moved to another area... idk.
    thank you for the video.

  • @henrik3098
    @henrik3098 7 місяців тому

    Great video Shawn! =)

  • @rankarat
    @rankarat 7 місяців тому

    Thanks that's was really helpful.

  • @rockycaballero5676
    @rockycaballero5676 7 місяців тому +1

    Great content Shawn, always joyful to see your content sir. Hope you will cover also new API Identity endpoint. Thanks and God bless :)

    • @swildermuth
      @swildermuth  7 місяців тому +1

      Already did: ua-cam.com/video/owoy6DG0UG0/v-deo.htmlsi=VYkeJIFfLOy4IE_E

    • @rockycaballero5676
      @rockycaballero5676 7 місяців тому

      ah I see. thanks :-)

  • @dasokume9411
    @dasokume9411 7 місяців тому +1

    awesome content

  • @poteb
    @poteb 7 місяців тому

    Much more cleaner than creating your own middleware and try/catch the MoveNext call.

  • @PeacefulMindss
    @PeacefulMindss 7 місяців тому

    I like it, thank you.

  • @user-nv4sh1ie7m
    @user-nv4sh1ie7m 6 місяців тому

    .net aspire would be a good one from you shawn

  • @DannyHille
    @DannyHille 6 місяців тому

    Hi Shawn Nice video good example!
    Video idea: I constantly see people overusing the dotnet mediator pattern, even for small monolithic apps. I'm not saying never use it, but only use it if you really need the decoupling.
    The most common excuse for using it is for unit testing, or "it's best practice." I call BS. Besides, it's a PITA to debug badly written mediator components (for well-structured projects with good naming conventions, it can be less of a pain, though).
    I'd like to hear your opinion on that.

  • @stevestrong9363
    @stevestrong9363 7 місяців тому

    Shawn , thanks for keeping us put to date is small practical and useful videos. I do not think any anyone has done a good treatment of object cloning, from the simple case to the shared reference case, so many ways to do it, reflection, code generation , Dehydrate - Hydrate, it could be a good series of videos

  • @jawwadalam
    @jawwadalam 7 місяців тому

    Thank you for explaining this.
    So I am assuming we can register multiple exception handlers and if that is the case will they follow any particular execution order like we see for middleware?

    • @swildermuth
      @swildermuth  7 місяців тому +1

      Didn't try, but I expect so.

  • @petropzqi
    @petropzqi 7 місяців тому

    Great video. Would love to see you deploy an aspire on a self-hosted environment, such as a raspberry pie and windows server 2016

    • @swildermuth
      @swildermuth  7 місяців тому +1

      Still getting my head around Aspire and it's use cases. When you say 'self-hosted' - do you mean called from the command-line?

  • @galberts
    @galberts 7 місяців тому

    Hy Shawn, always like your content, appreciated! As for suggestions: what would be a smart way to implement authorization in Blazor based on the ClientId the user is in combined with his/her role for that client. I guess Policy based authorization with AuthorizationHandler and PolicyHandler would be the one to use (check role) but how to combine specifying checking role and ClientId together? Ideally one would do [Authorize(Roles = "Administrator", ClientId = _clientId)], but the last parameter is not possible (is my fantasy).

    • @swildermuth
      @swildermuth  7 місяців тому

      Not sure how it works in Blazor, I use claims, but where you create the claims is based on how you're doing Authentication.

  • @JuanOG
    @JuanOG 7 місяців тому +1

    I think using the hellangs problem details middleware is more useful for real world exception handling especially when we have to handle specific exceptions.

    • @swildermuth
      @swildermuth  7 місяців тому

      Depends on what you want to do. But, since I haven't worked with it, I can't comment on how it works. It looks more like a way to log exceptions than to actually deal with them. But I get your point.

    • @S3Kglitches
      @S3Kglitches 7 місяців тому

      Yeah this. Returning ProblemDetails structure with status code based on exception subclass is the way to go.

    • @S3Kglitches
      @S3Kglitches 7 місяців тому

      ​ @swildermuth How have you handled exceptions on REST API so far in a standard way (RFC 9457) then if you haven't used that? It's basically a thing which is missing in ASP NET Core REST APIs

  • @k3davis
    @k3davis 4 місяці тому

    This is an interesting pattern. One thing I missed is the scope of the exception handler - is it intended to handle every exception in your whole project, or just incoming http requests? For example would you have to use the httpcontext inside TryHandleAsync to limit its behavior to, say, just paths that start with /api (exposed endpoints)?

    • @swildermuth
      @swildermuth  3 місяці тому

      It handles unhandled exceptions. It's the last line of defense, not used to avoid exception handling in your endpoints.

  • @vesnx
    @vesnx 7 місяців тому

    this .http file is cool, I guess PostMan and Fidler do not think so but me as a developer... love it

  • @jorgepedraza1275
    @jorgepedraza1275 7 місяців тому

    Any Repository related to this video? Thx

  • @siavash2176
    @siavash2176 7 місяців тому

    Hopefully it will not throw another exception when you set response status code, I had this experience with old exception handler middleware, sometimes it throws exception when you set the response status code and it says that status is already set or response is already begun.

  • @syllabailo6006
    @syllabailo6006 7 місяців тому

    Thanks Mr Shawn for your help with youtub and plurilsigh, please do you have a private learning center where people can change idea and learn ?

    • @swildermuth
      @swildermuth  7 місяців тому +2

      I am considering creating a discord for fans. Subscribe and you'll find out when it goes live.

    • @syllabailo6006
      @syllabailo6006 7 місяців тому

      @@swildermuth ok sir thanks

  • @SaeedBalkhair
    @SaeedBalkhair 7 місяців тому

    how can i run two project of dontnet (asp mvc and api) in same time in vscode?

    • @swildermuth
      @swildermuth  7 місяців тому +1

      Best way is to just use two terminal windows and call "dotnet run" in each folder

    • @SaeedBalkhair
      @SaeedBalkhair 7 місяців тому

      @@swildermuth 👍

  • @youshasajjad5402
    @youshasajjad5402 5 місяців тому

    hi is there anyway i can use parameterized Mappers in dotnet core?

    • @youshasajjad5402
      @youshasajjad5402 5 місяців тому

      if so how do i register those mappers?

    • @swildermuth
      @swildermuth  5 місяців тому

      Maybe, can you explain what you mean? I think Mapster and AutoMapper support something like that, but I am not sure exactly what you mean?

  • @bernpaul9868
    @bernpaul9868 Місяць тому

    what advice you would giive to a seasonal dotnet developer like me ? or a beginner T_T my mind is sooo overwhelmed with a lot of informations need to understand

    • @swildermuth
      @swildermuth  Місяць тому

      You don't have to drink through the firehose. Focus on making code that accomplishes the task .

  • @UmmarFarooqMahroof
    @UmmarFarooqMahroof 7 місяців тому

    hey can you do a quick video of VSCode, .NET MAUI dev with the C# devkit, either you or the legendary Scott Hanselman....please

    • @swildermuth
      @swildermuth  7 місяців тому +1

      I don't have the Maui experience I'd need to do it. But I'll throw it on my list to see if I can do it.

    • @UmmarFarooqMahroof
      @UmmarFarooqMahroof 7 місяців тому

      @@swildermuth much appreciated and thank you, actually I think I need to pester @jamesmontemagno

  • @unskeptable
    @unskeptable 6 місяців тому

    Exception handler is throwing an exception. 😂 That is such a Microsoft thing to happen

  • @leftjabrighthook
    @leftjabrighthook 7 місяців тому +2

    Dude…. Put the camera down step away from the computer and go outside and get some physical activity in. Exceptions don’t mean shit if you are dead.

    • @swildermuth
      @swildermuth  7 місяців тому +1

      Wait, am I fat? I never noticed. This sort of post ends up shaming and not supporting people. It's more complex than that.

    • @allenleggett4361
      @allenleggett4361 3 місяці тому

      @@swildermuth As my grandmother said, "Beauty is only skin deep. UGLY goes straight through to the bone!" - We love you Shawn, you are beautiful to us. Thanks for all you do - and the crap you put up with while making the world a better place.

  • @kfathi1
    @kfathi1 7 місяців тому

    nice