To handle errors and enable logging in the CADK, use the following recommendations:
A Java manipulator or a content adapter that you create should be implemented to throw an
AdapterException
if an error (such as failing to connect to a data source) occurs. Forge logs the message portion of the exception with a log level oferror
. If a Java manipulator or a content adapter simply wants to quit without issuing an error in Forge, it should return from theexecute
method.Never implement a Java manipulator or a content adapter to call
System.exit
.The
AdapterHandler
may throw anAdapterException
, which, in general, should not be caught by a Java manipulator or a content adapter. However, in some cases it may be necessary to catch this exception (usually for the purpose of formatting the error message).Catching and re-throwing the message is acceptable. If you are doing so, it is important to note that the
AdapterHandler
throws a sub-class ofAdapterException
,ShutdownRequestAdapterException
, which is used to signal that Forge will not process any more records. This can happen under several scenarios, the most common of which occurs when Forge is run with the-n
flag.If the
ShutdownRequestAdapterException
is caught and anAdapterException
is thrown in its place, Forge logs an error message. Normally this is not the desired effect. To avoid this, a content adapter’stry ... catch
block should be similar to the following:try { ... adapterHandler.emit(record); } catch (ShutdownRequestAdapterException e) { throw e; } catch (AdapterException e) { throw new AdapterException(reformat(e.getMessage())); }
A
try ... catch
block of this form does not log an error message in Forge if theShutdownRequestAdapter Exception
is thrown by theAdapterHandler
.In general, once the
AdapterHandler
throws an exception, further calls toAdapterHandler.emit
are likely to trigger additional exceptions.