rundb / javafiddle

SImple Web-based Java IDE.
GNU General Public License v2.0
0 stars 2 forks source link

Exceptions in services #35

Open atsanda opened 8 years ago

atsanda commented 8 years ago

There's a much more elegant way of handling exceptions in RS. This way is not reusable and looks a bit dirty. Please find a good guide here: http://www.codingpedia.org/ama/error-handling-in-rest-api-with-jersey/

Short summary: 1) Jersey (javax.ws.rs implementation in Glassfish) has an OOB mechanism of exception handling, more generic than writing try/catch for each particular service method. 2) By default Jersey handles runtime exceptions by wrapping them into WebApplicationException. 3) If you prefer more control, use the examples on the link I gave above.