0% found this document useful (0 votes)
3 views

Error & Exception Handling

Uploaded by

devaanirudh323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Error & Exception Handling

Uploaded by

devaanirudh323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Error & Exception in Spring WEB-MVC :-

• Error and Exception are the unwanted events that occurs during the excecution of our
program
• In Spring WEB-MVC, we can handle the error or exception by 3 ways :-
1. By web.xml file
2. By pre-defined class (SimpleMappingExceptionResolver)
3. By annotations (@ExceptionHandler)

1. Handling exception using web.xml


 If any 404 error occurs then it will send request to /pageNotFound
 If any ArithmeticException occurs it will send request to /arithmeticException

 The above sended requests will go to the controller and the controller will open
the corresponding page
2. Handling exception using pre-defined classes

If this exception occurs


then it will automatically
opens this page

This can handle any type of exceptions

3. @ExceptionHandler :-
• It is used to define a method that handles exceptions which are thrown by the other
methods in the controller
• It provides a way to centralize the exception handling and present a consistent response
to the client in case of errors

You might also like