4043   Result of expression overflows Decimal precision

Cause

This error occurs when a decimal overflow condition occurs if the truncateOnDecimalOverflow method of the Process class is called with a parameter of true.

This error differs from error 4033 - Result of expression overflows decimal precision in that this error is continuable.

If an exception handler continues this exception, the decimal number is truncated and execution continues. For example, the value 123.456 is truncated to 23.46 when assigned to a Decimal [4, 2].

Action

For an example of using this continuable exception, consider the following code.

vars
    d : Decimal[4,2];
begin
    on Exception do e0(exception);
    process.truncateOnDecimalOverflow(true);
    d := 123.456;
    write d;
    d := -123.456;
    write d;
end;

In the above method, e0 is defined as follows.

e0(e : Exception): Integer;
begin
    // exception 4043 is a 'continuable' decimal overflow
    if e.errorCode = 4043 then
        // continuing here will result in the value being truncated
        return Ex_Continue;
    endif;
    return Ex_Resume_Next;
end;

The output of the write instruction using these examples is as follows.

23.46
-23.46

It is the integral part of the decimal that is truncated. The fractional part is rounded.

Note also that the extended error text of the exception contains the value of the decimal before it is truncated. The following method is an example of an exception handler.

e0(e : Exception): Integer;
begin
    // exception 4043 is a 'continuable' decimal overflow
    if e.errorCode = 4043 then
        write e.extendedErrorText;
        // continuing here will result in the value being truncated
        return Ex_Continue;
    endif;
    return Ex_Resume_Next;
end;

The output from the above method is as follows.

123.456
23.46
-123.456
-23.46