Junos Space SDK > Developer Guides > Junos Space Application Developer Guide > Programming with the Junos Space SDK > Developing Junos Space Applications > Creating REST Services

Handling Exceptions

Exceptions enable a user to know that some error condition has occurred in the system. Most Exceptions which might occur in the REST Layer are automatically handled by Resteasy or the Junos Space JMPExceptionMapper and do not need to be explicitly handled by the EJB code. However, there are certain Java Checked Exceptions that need to be handled in the EJB layer, and subsequently converted to Standard HTTP Status Codes in the REST layer. This is achieved with the help of Resteasy's Exception Handling framework and a custom ExceptionMapper described in that document. The Junos Space framework already includes a custom Resteasy Exception Mapper, which maps some known Java Exception classes to their corresponding HTTP Error Codes. These are:

These exceptions can be explicitly thrown by the custom EJB logic to trigger HTTP status codes (designated in parenthesis) to be returned.  Other HTTP error codes are automatically generated when an error condition arises, and don't need to be explicitly handled by user code.  These error codes (along with their usage) are listed in the Standard HTTP Status Codes table.

Some of these exception are also explicitly handled by the Web Service code generated by the EJB-REST Wizard. These exceptions are: