class DemoController String controllerForArithmeticException() It is not a good practice to leave the exceptions unhandled as it reveals the details of our internal system to the browser (client). Now let's add a try-catch block to handle the exception as we don't want that our browser receives the exception details. Response in postman: ( Status: 500 Internal Server Error Throw new ArithmeticException("Divide by zero error") Let's start with the example: class DemoController String controllerForArithmeticException() In the sample application, we are having only a controller in which we are manually throwing an exception to replicate the flow of any normal microservice. Suppose we are designing a simple microservice with a controller, service and DAO class, where all the exceptions are being handled in the controller itself, whether it occurs in the service, DAO, or the controller itself. The most common way to apply exception handling in our code is by using try catch blocks. In software development, exception handling is a way or mechanism to handle any abnormality in the code at runtime in order to maintain the normal flow of the program.
0 Comments
Leave a Reply. |