How to implement global exception handling in ASP .NET Core Web API 7.0

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to my channel in this session we are going to see how we can handle our exception in the application Level or globally using our asp.net core 7.0 web API I have already created a video how to handle exception globally on asu.net core 6.0 if you want to visit that one I will give the video description a link on video description as well as the I button please check it out guys before starting the session if you are new to my Channel please hit the Subscribe button and ring the bell icon for future notification and if you ended up liking my videos give me a like so that YouTube will know and it will promote to other viewers let's get started exception handling and exception is a problem arise during the execution of a program a c sub exception is the response to a exceptional circular classes that arise while program is running such as attempt to divide it by a zero it will be infinite an exception provide a way to transfer control from one part of a program to another csap exception handling is built in upon four keyword try catch finally and throw we are going to use the key this keyword also and there is the huge exception Handler middleware is built in middleware in.net core that can use to handle exception with the I exception handle feature okay so let's see how we can use try catch finally on Pro and how we can use exception Handler and I exception Handler feature for that I am today I am using visual studio 2022 or 2022 to create a new project and I will be creating a asp.net core web API and I'm giving let's say Global exception handle guys okay now let's click on create all right for now I know universities for now on no need to open apis or Swagger support let's create guys this will be just five to six lineup code to modify your click application if you are net core 6.0 if you are running on.net core 5.0 if you're running.net or 7.2 this 5269 of code can manage your exception completely or complete application globally so our application Got Run so here you can see in the controller section whether forecast controller is created so this is the get API if I am running the application now this get API will hit and it will generate me a random five days record for the weather forecast as it is the template is working let's run the application it will take few seconds because we are running the first time guys I have one request and don't get mind on this and please don't skip the ads and recently I'm getting started monies please don't skip please okay so this is my web API I am getting a the five Dash random record for now let's say I am adding a through exception okay throw new exception here I am adding okay you can Define accession here no need of this line now let's comment it now for now let's run the application so we are giving through new exception user find exception here so a valid message can we can give right so you can see by running this one it is going getting throwing just click on continue and we will see the error right a big error so we are if we are giving the API to third party and we are showing this kind of big error and sometime there are database table name sometimes the column name and sometimes different other entities data it is bad right if you are going with strike age let's say we are going with like now here hi guys so we will handle our exception here with okay now let's run continue again we have to see this kind of big message and we have to write try catch to our complete all the API let's say we have hundred of API we have thousands of API we have to write trackish to all the apis what if we can do in a single line of code or just a single code stop the application for now I now need a try catch now okay save it now open our program.cs file after up Builder dot build here we can configure our pipeline how we can configure our pipeline of Dot use exception Handler right inside this you can write options it extend to inside this option dot ROM inside this we can write like this async context context response status code it will be internal server error and it will be the feature will be accessible feature I access some Handler feature and ever dot concept right async exception of the vat X error.message now let's run the application and we will see how the error is coming continue you can see no extra data simple user defined error message came here so in this way we can handle our exception globally through our program.cs file using huge exception Handler by built-in pipeline by dot net core guys I hope you like this session if you do give me a like and share this video with your friends thank you very much
Info
Channel: Biswa Ranjan
Views: 2,285
Rating: undefined out of 5
Keywords: Exception handling, global exception handling, Exception handling in .Net Core 7.0, global exception handling in .Net Core 7.0, Exception, ASP.NET CORE, WEB API, DotNet CORE, core, .Net Core 7.0, .Net Core 7.0 JWT Token, .Net Core 7.0 Exception, Dot Net Core 7.0, Dot Net Core 7.0 Exception, .Net Core 7.0 Web API JWT Token Authentication, Dot Net Core 7.0 Web API, Learn Programming Online, LearnProgrammingOnline, Learn .NET, Learn Dot Net
Id: YSAmDs_V7gU
Channel Id: undefined
Length: 7min 50sec (470 seconds)
Published: Tue Jun 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.