Learn how exception filters help you create reusable exception handling logic.
- [Instructor] It could handle most exceptions…by putting code right inside our controller actions,…but doing it that way in a larger application…would lead to lots of copy-and-pasted code.…It would be better if we could create a reusable piece…of exception-handling logic that then we apply…to the controllers and action methods in our code…without having to copy and paste the actual code itself.…Fortunately, WebAPI provides just such a feature,…and it's called exception filters.…Let's create an exception filter for the situation…we were looking at earlier.…
If SQL server is expecting a certain non-primary key field…to be unique because of a unique constraint that's on…that table, it won't actually throw that exception…until we try and either insert or update a record…that would actually violate that constraint.…In which case, Entity Framework will catch the exception…and bubble it up to us as a DB update exception.…We'll start creating a filter for this situation…by creating a class, and we'll call this…DbUpdate…
AuthorJonathan "J." Tower
- Convention-based routing
- Binding your code to an HTTP request
- Validating models
- Using attributes to route requests
- Customizing attribute routes
- Data serialization and model binding
- Error handling
- Using exception filters and exception loggers
- API documentation and testing
- Securing your API
Skill Level Beginner
ASP.NET MVC: HTTP Request Life Cyclewith Janan Siam2h 15m Advanced
1. Controllers and Actions
3. Data Serialization and Model Binding
4. Error Handling
5. API Documentation and Testing
Next steps1m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.