Skip to content

lnardulli/exception-java-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exception Java example

This Java project shows you how to catch custom exceptions. This project was done with Spring Boot 2 to take advantage of the annotation.

Exceptions

We have an ExceptionGlobalResponse to catch RuntimeException and Exception an annotation through the @ControllerAdvice annotation. We also created the YoungAgeException class that contains my own RuntimeException exception.

To throw customize exception

//throw with object
throw YoungAgeException.of(young);
//throw with specific message
throw new YoungAgeException("Age cannot exceed");

When that type of exception is thrown, ExceptionGlobalResponse catches because it has the @ExceptionHandler with this specific YoungAgeException annotation and displays a custom response.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors