message.error¶
Signature: message.error(errorMessage, exception*)
Returns: void
Error the current message and terminate processing immediately. When this is called all remaining mapping functions are skipped and the message is sent to error queue.
Note
If you catch an error with JavaScript via catch(err), the Java exception is accessed with 'err.javaException'.
Note
This method only applies to the following formatted messages: HL7, ASTM, Binary, CSV, DICOM, EDIFACT, Old Fxd Width, Fxd Length, ISO 8583, JSON, Text, X12, XML.
Parameters¶
| Type | Name | Description | Default |
|---|---|---|---|
| String | errorMessage | the error message to display in the error queue | |
| String or Throwable | exception* | (optional) the error or java.lang.Throwable exception that caused the error | null |
Example¶
// Example: Terminate processing and send the message to the error queue.
var result;
// Example: errorMessage only
try {
// Execute logic that may throw an exception
result = someFunctionThatMayFail();
} catch (err) {
message.error(
"An error occurred while processing the message" // errorMessage
);
}
// Example: errorMessage + Java exception
try {
// Execute logic that may throw an exception
result = someFunctionThatMayFail();
} catch (err) {
message.error(
"An error occurred while processing the message", // errorMessage
err.javaException // exception (Throwable)
);
}
// Example: errorMessage + custom Java exception
try {
// Execute logic that may throw an exception
result = someFunctionThatMayFail();
} catch (err) {
message.error(
"Custom failure occurred",
new java.lang.Exception("Something went wrong") // exception (Throwable)
);
}