Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring to throw an exception without ever throwing it

I have a couple of EJBs that are called from a jax-rs web service. However, every time I call one of the EJB methods I am intercepting the invocation using an interceptor. This interceptor checks the parameters for an API key and if it is not present or doesnt exist in my database it will throw an exception that I wish to catch in my jax-rs code. However, since my jax-rs class has no knowledge of the possibility of this exception being thrown even though the exception could be a checked exception, what would be the best practice here?

  1. Declaring my EJB to throw exceptions (without ever throwing them itself)
  2. Making my exception an unchecked exception and checking for it anyways?
  3. Something else?
like image 656
Terabyte Avatar asked Nov 08 '22 16:11

Terabyte


1 Answers

I figured out that throwing an unchecked exception would be the best. I then use an exception mapper to catch the exception and handle it.

https://docs.oracle.com/javaee/6/api/javax/ws/rs/ext/ExceptionMapper.html

The only thing that's left is to suppress the exception output to the log files.

like image 186
Terabyte Avatar answered Nov 14 '22 23:11

Terabyte