Apama 10.1 | Apama Documentation | Developing Apama Applications | EPL Reference | Types | Reference types | Exception
 
Exception
Values of Exception type are objects that contain information about runtime errors.
Usage
The Exception type is defined in the com.apama.exceptions namespace. Typically, you specify using com.apama.exceptions.Exception so you can easily refer to Exception objects.
An Exception object has methods for accessing an error message, an error type, and a sequence of com.apama.exceptions.StackTraceElement objects that show where the exception occurred and what the calls were that led to the exception.
Exceptions can be constructed with the Exception constructor, which takes a string for the message and a string for the exception type. Any string can be used for the type, but it is recommended to re-use one of the types generated by the correlator when appropriate. For example:
throw Exception("No readings", "IllegalArgumentException")
You cannot route an Exception object, but a routable object can have an Exception object as a member.
Methods
The following methods may be called on values of Exception type:
*getMessage()Returns a string that contains the exception message.
*getStackTrace()Returns a sequence of StackTraceElement objects that represent the stack trace for when the exception was first thrown. The sequence is empty if the exception has not been thrown.
*getType()Returns a string that contains the exception type. This can be one of the following:
Exception Type
Description
ArithmeticException
Illegal arithmetic operations.
Example: Attempt to divide by 0, call to the ceil() method on NaN, call to the exponent() method on infinity, specifying NaN as all or part of an ordered key, call to the rand() method on an illegal float value such as Infinity.
CastException
Thrown when casting an any value to a type which does not match the type of the any value.
Example:
any a := 1;
string s := <string> a;
DefaultContextException
Spawning, sending or enqueuing to a context and specifying a context variable that has been declared but the context has not yet been created.
Example:
monitor m {
context c;
action onload()
{
send A() to c;
}
}
IndexOutOfBoundsException
Invalid index in a sequence or string operation.
Example:
sequence.insert(-1, x)
IllegalArgumentException
Illegal argument value in an expression.
Example:
"".split()
IllegalStateException
Calling an action when it is illegal to do so.
Example: A spawn statement in ondie() or onunload().
MemoryAllocationException
Unable to fulfill memory allocation request.
Example: An invalid size is passed to the sequence setCapacity() method.
NullPointerException
Attempt to call an action variable when that variable has not been initialized, or to call getOrThrow on an optional instance that is empty.
Example:
event E {
action<string> x;
}
monitor m {
E e;
action onload() {
e.x("This will fail!");
}
}
OtherInternalException
An internal error occurred.
Example: parse("two") on an integer.
ParseException
Error that occurs while parsing.
PluginException
An exception thrown by an EPL plug-in. See the information that follows this table.
StackOverflowException
Attempt to use more space than is available on the stack.
UnmatchedTypeException
Thrown by the switch statement if none of the case clauses match the type of the any value and there is no default clause (or the any is an empty value). See also Handling any values of different types with the switch statement.
Example:
any a:=any();
switch(a) {
case string : { print "string"; }
case integer : { print "int"; }
}
In EPL plug-ins that are written in C++, you can customize exception types so that the type returned has this format:
PluginException:user_defined_type
See AP_UserPluginException in the correlator_plugin.hpp file in the include folder of your Apama installation.
In Java plug-ins, the exception type returned has this format:
PluginException:class_name
For example:
import "MyJavaPlugin" as myjavaplugin;
...
action myAction() {
try {
myjavaplugin.processfile("config.txt");
} catch (Exception e) {
log "Exception of type "
+ e.getType() at WARN;
}
}
...
Returns something like:
Exception of type
PluginException:java.io.FileNotFoundException
*toString()Returns a string that contains the exception message and the exception type.
*toStringWithStackTrace()Returns a string that contains the exception message, the exception type, and the stack trace elements.

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.