ILE C/C++ Programmer's Guide

Differences in Error Checking

This section describes error checking for:

Invalid Decimal Format

In ILE C, packed decimal is implemented as a native data type. This allows an error such as invalid decimal format to be detected at compile time.

In C++, detection of a similar error is deferred until run time, as shown in the following examples:

#define _DEBUG 1
 
#include <bcd.h>
 
int main ( void )
{
 _DecimalT<10,20> b= __D("ABC"); // Run-time exception is raised
}

and

#define _DEBUG 1
 
#include <bcd.h>
 
int main ( void )
{
  _DecimalT<33,2> a;            // Max. dig. allow is 31. Again,
                               // run-time exception is raised
}
Note:
Some errors can be detected at compile time, for example: n<1, (_Decimal<-33,2>).

Mathematical Operators

ILE C provides additional error checking on the sign or the digit codes of the packed decimal operand. Valid signs are hex A-F. Valid digit range is hex 0-9. If the decimal operand is in error, ILE C generates an error message. This additional checking is not present in the _DecimalT class template.

The following code results in an error message in ILE C but not in ILE C++:

#include <decimal.h>
 
int main ( void )
{
   decimal(10,2) a, b;
   int c;
   c = a >  b;   // a and b are not valid packed decimals because
                 // a and b are not initialized
}


[ Top of Page | Previous Page | Next Page | Table of Contents ]