What's New in Apama > What's New in Apama 5.1 > New EPL exception handling mechanism
New EPL exception handling mechanism
EPL now supports the try-catch exception handling structure for processing runtime errors. The try-catch statement's BNF definition is:
tryCatchStatement ::= try block1 catch(Exception variable) block2
The statements in each block must be enclosed in curly braces. For example:
using com.apama.exceptions.Exception;
...
action getExchangeRate(
dictionary<string, string> prices, string fxPair) returns float {
try {
return float.parse(prices[fxPair]);
} catch(Exception e) {
return 1.0;
}
}
An exception that occurs in try block1 causes execution of catch block2. Two new data types have been added to support exception handling:
*com.apama.exceptions.Exception — A variable of this data type contains an exception message and an exception type. It also contains a sequence of com.apama.exceptions.StackTrackElement objects. The sequence represents the stack trace for when the exception was first thrown. Exception objects have methods for accessing the exception message, the exception type, and the stack trace.
*com.apama.exceptions.StackTraceElement — A variable of this data type contains information for one stack trace entry. A StackTraceElement object has methods for accessing the details for the stack trace entry it represents.
try, catch and throw are now keywords. If you want to use one of these words as an identifier you must prefix it with a hash symbol (#), otherwise it is an error.
For details, see Developing Apama Applications in EPL, Defining What Happens When Matching Events are Found, Catching exceptions.
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.