SourcePro Analysis : Currency Module User’s Guide : Errors and Error‑Handling
Errors and Error‑Handling
Overview
The operations on RWDecimal classes can result in three general types of error:
*Overflow. This type of error occurs when the result cannot be represented with the available number of digits. For example, the following code fragment causes an overflow:
 
RWDecimal<RWMP2Int> a = “10000000000” * “10000000000”;
*Loss of precision. This type of error occurs when the number cannot be represented exactly, but can be represented approximately by reducing the number of digits after the decimal place. This is also called an inexact error, because the number resulting from the calculation is not the exact solution. For example, in the following the 20 decimal digits necessary cannot be represented:
 
RWDecimal<RWMP2Int> b = “1.0000000001” * “1.0000000001”;
*Numeric errors. This error includes problems such as division by zero.
In the Currency Module library, if an overflow or an inexact error occurs during one of the three exact arithmetic operations, an error handler is called. The default overflow error handler throws an RWDecimalOverflowErr<T> exception object, or prints an error and exits if your compiler doesn't support exceptions. The default inexact error handler prints an error message but does not exit. In Error-Handling , we’ll describe how to change these default behaviors.
Remember, you can perform operations on different currencies if you use a money calculator object. However, if you an attempt to perform an arithmetic operation on RWMoney objects of different currencies the operator throws an RWExternalErr exception. See the Essential Tools Module documentation for information on RWExternalErr.
If the factory cannot create an exchange object, it returns an invalid exchange object -- for example, if you request a conversion from French Francs to French Francs.