From the course: Java EE 7: Web Services

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Incorporate error handling

Incorporate error handling - Java EE Tutorial

From the course: Java EE 7: Web Services

Start my 1-month free trial

Incorporate error handling

- [Instructor] Now let's look at handling exceptions. Exceptions may be thrown from within the API, and propagated to the client. I've opened the project in IntelliJ, and I've navigated to the ApplicationResource.java file. And now let's scroll down to line 40 and look at the addApplication method. So let's talk about this. In previous versions of this method I was catching the SQLIntegrityConstraintViolationException, and returning a response code of 409, which represents a database conflict because a record already exists. Now, I've updated the code to remove that try catch block, and now I'm using what's called an exception mapper. And notice here on line 40 I've updated the code to throw a sql exception. Now let's navigate to the SQLIntegrityConstraintViolationExceptionMapper. And now let's talk about how this works. So an exception mapper knows how to map a thrown application exception to a response object. The use of an exception mapper allows me to deal with a certain type of…

Contents