Error Handling

CTL2 also provides a simple mechanism for catching and handling possible errors.

However, CTL2 differs from CTL1 as regards handling errors. It does not use the try-catch statement.

It only uses a set of optional OnError() functions that exist to each required transformation function.

For example, for required functions (e.g., append(), transform(), etc.), there exist following optional functions:

appendOnError(), transformOnError(), etc.

Each of these required functions may have its (optional) couterpart whose name differs from the original (required) by adding the OnError suffix.

Moreover, every <required ctl template function>OnError() function returns the same values as the original required function.

This way, any exception that is thrown by the original required function causes call of its <required ctl template function>OnError() counterpart (e.g., transform() fail may call transformOnError(), etc.).

In this transformOnError(), any incorrect code can be fixed, error message can be printed to Console, etc.

[Important]Important

Remember that these OnError() functions are not called when the original required functions return Error codes (values less then -1)!

If you want that some OnError() function is called, you need to use a raiseError(string arg) function. Or (as has already been said) also any exception thrown by original required function calls its OnError() counterpart.