Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Currency Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

8.4 Error-Handling

The most common errors associated with the RWDecimal<T> classes are inexact errors and overflow errors. The Currency Module library provides a mechanism that lets you customize how these errors are handled.

8.4.1 Installing an Inexact Error Handler

Inexact errors occur when a number can't be represented exactly with the available number of digits, but can be approximated by reducing the number of digits after the decimal. When addition, subtraction, or multiplication result in an inexact error, an RWDecimalInexactErr<T> object is created and passed to an error handler.

By default, an inexact error results in an error message being printed and execution resuming. You can substitute a different action by supplying your own handler. Here is an example:

8.4.2 Installing an Overflow Error Handler

An overflow error occurs when a number cannot be represented with the available number of digits. For example 10ˆ30 cannot be represented in the RWDecimal<RWMP3Int> class as it has too many digits. When an operation results in an overflow error, an RWDecimalOverflowErr<T> object is created and passed to an error handler.

The default overflow handler will print an error message and throw the error object as an exception. If your compiler does not support exceptions, then the RWThrow error handler is called to simulate an exception.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.