Let's create a resource that throws an exception, and send a GET request to it in order to understand how the application reacts to runtime exceptions.
Let's create a dummy service that throws an exception. The following code snippet shows a simple service:
@GetMapping(path = "/users/dummy-service") public Todo errorService() { throw new RuntimeException("Some Exception Occured"); }
Some important things to note are as follows:
- We are creating a GET service with the URI /users/dummy-service.
- The service throws ;RuntimeException. We chose RuntimeException to be able to create the exception easily. We can easily replace it with a custom exception ;if needed.
Let's fire a GET request to the preceding service ...