In C++, 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 Money.h++ C++ 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 Section 8.4, we'll describe how to change these default behaviors.
In the Money.h++ Java library, these three conditions result in a call to the error handler with a PrecisionExceededException error, described in the API documentation. Section 8.4.3 describes how to adjust the behavior of the error handler.
Remember, in both Java and C++ you can perform operations on different currencies if you use a money calculator object. However, if you an attempt to perform an arithmetic operation in C++ on RWMoney objects of different currencies the operator throws an RWExternalError exception. See the Tools.h++ documentation for information on RWExternalError. In Java, attempting to use two Money objects of different currencies in a calculation calls the error handler with MismatchedCurrenciesException.
In C++ if the factory cannot create an exchange object, it returns an invalid exchange object. If the same problem occurs in Java, the factory returns a null value. Java applications send an InvalidExchangeException error to the error handler if an illogical exchange object is requested from the ExchangeFactory, for example, if you request a conversion from French Francs to French Francs. An InvalidExchangeException error also occurs if the MoneyCalculator is asked to make a currency conversion and is unable to find an appropriate currency exchange object.
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.