Master Exception Handling in Spring Boot: @ExceptionHandler & @ControllerAdvice Explained

  Рет қаралды 2,765

CodeSnippet

CodeSnippet

Күн бұрын

Пікірлер: 9
@AdarshSingh-j1q
@AdarshSingh-j1q Ай бұрын
Don't use dark theme, In intelij and postman, Unable to see text.
@CodeSnippet.java.
@CodeSnippet.java. Ай бұрын
Noted. Thanks for feedback
@universal4334
@universal4334 Ай бұрын
Let's say in my service class, I'm doing multiple operations to return something to controller. Out of those many operations in service, i may get 10 different exceptions, so do i need to catch specific exceptions or directly catch generic exception in service and throw our custom exception, so that even we don't handle specific exception or anything in controller, restcontroller advice catches our custom exception
@CodeSnippet.java.
@CodeSnippet.java. Ай бұрын
Great question! It's a good practice to catch specific exceptions as much as possible in your service layer, as it gives more clarity on what went wrong and helps you handle different scenarios appropriately. However, if you have several different exceptions, you can group them and map them to a custom exception, which can then be handled by the @ControllerAdvice. For example, you could catch specific exceptions like NullPointerException, IllegalArgumentException, etc., in your service, then wrap them in a custom exception (e.g., CustomServiceException). This custom exception can be handled centrally in @ControllerAdvice. Catching a generic Exception directly in the service might hide the actual problem, making debugging difficult. Always try to handle known exceptions first, then fall back on generic handling if necessary. This way, your @ControllerAdvice can consistently handle the custom exception and return a proper response to the client.
@kapilpandey806
@kapilpandey806 Ай бұрын
How much time to enough to learn spring boot from scratch? And what should I need to learn for 2 to 3 year experience person . Earlier worked on core java and SQL .please guide me
@mahady_hasan_fahim
@mahady_hasan_fahim Ай бұрын
Thanks you. I learn new topics from your video. But you don't provide source code -_-
@CodeSnippet.java.
@CodeSnippet.java. Ай бұрын
I have updated project link in description
@ijaysingh5762
@ijaysingh5762 Ай бұрын
can you provide notes
@CodeSnippet.java.
@CodeSnippet.java. 18 күн бұрын
Sure
Exception Handling in Spring Boot REST API Explained With Demonstration
28:05
КОГДА К БАТЕ ПРИШЕЛ ДРУГ😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 20 МЛН
СОБАКА ВЕРНУЛА ТАБАЛАПКИ😱#shorts
00:25
INNA SERG
Рет қаралды 1,7 МЛН
ЗНАЛИ? ТОЛЬКО ОАЭ 🤫
00:13
Сам себе сушист
Рет қаралды 4 МЛН
Spring Boot Exception Handling Made Easy
30:41
Bouali Ali
Рет қаралды 16 М.
Spring Annotations Explained: Comprehensive Guide with Examples
22:52
Svelte 5's Secret Weapon: Classes + Context
18:14
Huntabyte
Рет қаралды 25 М.
Logging in Spring Boot | Implementing Logging in Spring Boot application
50:48
КОГДА К БАТЕ ПРИШЕЛ ДРУГ😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН