Coding Shorts: ASP.NET 8 - New Exception handling

Coding Shorts: ASP.NET 8 - New Exception handling

Shawn Wildermuth

7 месяцев назад

14,933 Просмотров

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:
- https://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:
- https://www.youtube.com/playlist?list=PLtOvnDRdH12e3vOq4zvpI2cKsancIwMcP

Тэги:

#Web_Development #Azure #Azure_Static_Web_Apps #Static_Web_Apps
Ссылки и html тэги не поддерживаются


Комментарии:

@DannyHille
@DannyHille - 28.12.2023 17:13

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.

Ответить
@user-nv4sh1ie7m
@user-nv4sh1ie7m - 27.12.2023 00:02

.net aspire would be a good one from you shawn

Ответить
@poteb
@poteb - 29.11.2023 14:02

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

Ответить
@galberts
@galberts - 26.11.2023 21:30

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

Ответить
@stevestrong9363
@stevestrong9363 - 26.11.2023 16:59

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

Ответить
@rockycaballero5676
@rockycaballero5676 - 24.11.2023 10:16

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

Ответить
@StateHasChanged
@StateHasChanged - 24.11.2023 02:36

This is great! I can't seem to get this to work in Blazor 8 (mostly InteractiveServer pages). Anyone know if this is supported for Blazor 8?

Also, how does this differ from adding a delegate function (can't get either to work)...

app.UseExceptionHandler(new ExceptionHandlerOptions{
ExceptionHandlingPath = "/Error",
ExceptionHandler = context => GlobalExceptionHandler.HandleException(context),
});

Ответить
@Rhysling2
@Rhysling2 - 23.11.2023 03:14

Did not know about this. Thank you Shawn.

Ответить
@SaeedBalkhair
@SaeedBalkhair - 21.11.2023 23:09

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

Ответить
@petropzqi
@petropzqi - 21.11.2023 19:50

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

Ответить
@siavash2176
@siavash2176 - 21.11.2023 07:56

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.

Ответить
@Phonophobic
@Phonophobic - 21.11.2023 04:35

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

Ответить
@leftjabrighthook
@leftjabrighthook - 20.11.2023 18:32

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.

Ответить
@PortalUser2
@PortalUser2 - 20.11.2023 08:55

Thanks for bringing this to our attention Shawn. That is nice, but they should have made it an IExceptionHandler<TException> and passed in a strongly typed exception.

Ответить
@dasokume9411
@dasokume9411 - 20.11.2023 03:20

awesome content

Ответить
@larrye
@larrye - 18.11.2023 18:14

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.

Ответить
@rankarat
@rankarat - 18.11.2023 08:29

Thanks that's was really helpful.

Ответить
@jorgepedraza1275
@jorgepedraza1275 - 17.11.2023 22:59

Any Repository related to this video? Thx

Ответить
@kfathi1
@kfathi1 - 17.11.2023 11:47

nice

Ответить
@godfathermikal
@godfathermikal - 15.11.2023 17:52

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

Ответить
@mouradaissani8957
@mouradaissani8957 - 15.11.2023 11:33

Thank you Shawn

Ответить
@RizaMarhaban
@RizaMarhaban - 15.11.2023 10:40

Great video Shawn. I was wondering if the code is better using app.UseExceptionHandler("/"); compare to app.UseExceptionHandler(_ => {}); what do you think?

Ответить
@UmmarFarooqMahroof
@UmmarFarooqMahroof - 15.11.2023 06:33

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

Ответить
@jawwadalam
@jawwadalam - 15.11.2023 04:52

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?

Ответить
@etexas
@etexas - 15.11.2023 03:03

One idea I have as I watch this video,
could we somehow add logging in OurExceptionHandler?
Something like ILogger?
Thoughts?

Ответить
@syllabailo6006
@syllabailo6006 - 15.11.2023 01:42

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 ?

Ответить
@JuanOG
@JuanOG - 15.11.2023 00:51

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

Ответить
@PeacefulMindss
@PeacefulMindss - 14.11.2023 22:23

I like it, thank you.

Ответить
@henrik3098
@henrik3098 - 14.11.2023 22:09

Great video Shawn! =)

Ответить