Runtime errors
Even though SPL performs most of its error checking at compile time, runtime errors can still happen in some cases. When any runtime error occurs, the entire partition (execution container) enclosing the streaming operator invocation dies, writes the error to a PE trace or log file, and stops accepting new tuples.
- An invalid subscript for a list, blob, string, or map
- A size mismatch in the operands of mapped expression operators
- An integer division by zero
- Exceptions in libraries (such as C++ or Java™ exceptions)
To help the user with error handling, SPL provides APIs for assertions,
tracing, and logging. Assertions look like calls to an assert
function
with the following signatures:
void assert (boolean condition)
<string T> void assert (boolean condition, T message)
An assertion failure prints the message together with the line number to the trace file, and kills the enclosing partition. Unlike regular function calls, and like assertions in C or Java™, SPL assertions can be disabled. When an SPL program is compiled with assertions disabled, their parameter expressions are not evaluated, saving time and possibly runtime errors in the parameter expressions.
Besides assertions, SPL also provides other features to help testing and error handling.
The appTrc
function is used for application debugging,
and writes the trace message to a PE trace file for the application. For
example, if the SPL operator is running in PE 1, the trace data is
in pe1.out.x
(where x is
the number of the rolling trace file, with the .out
file that
contains the most recent trace data).
The appLog
function writes messages
to the Teracloud®
Streams product
log location. When your program writes messages to the product log,
do not write them for normal tracing and do write them with the administrator
in mind. Focus the message on why the problem occurred, and how an
administrator can resolve the problem.
The appTrc
and appLog
functions
have the following signatures:
// type spl::Trace.Level = enum { error, warn, info, debug, trace } ;
<string T> public void appTrc(enum {error, warn, info, debug, trace} level, T message)
<string T> public void appTrc(enum {error, warn, info, debug, trace} level, T message, T aspect)
// type spl::Log.Level = enum { error, warn, info } ;
<string T> public void appLog(enum {error, warn, info} level, T message)
<string T> public void appLog(enum {error, warn, info} level, T message, T aspect)
The value error
means that the trace
or log is unmaskable, whereas the values warn
, info
, debug
,
and trace
mean that tracing or logging is performed
when the user requested least verbose to most verbose tracing.
Besides assertions, tracing, and logging, SPL also
provides an abort()
function, which unconditionally terminates
the partition, even when compiled with assertions disabled.
log()
function is deprecated, and is replaced
with the appTrc
function.