Fraction Library
A C++ Fraction library.

FracError.h File Reference

This file defines error conditions that can result when using Fraction and MFraction classes. More...

Go to the source code of this file.

Defines

#define FR_DENOM_ZERO   ((FR_ERROR)1)
 A value FR_ERROR takes when a fraction's denominator is equal to 0.
#define FR_STR_INVALID   ((FR_ERROR)2)
 A value FR_ERROR takes when a string value can't be converted into a fraction.
#define FR_INDEX_OUT_BOUNDS   ((FR_ERROR)3)
 A value FR_ERROR takes when index is out of bounds when using the [] operator to access the private member variables.
#define FR_NEG_PARAM   ((FR_ERROR)4)
 A value FR_ERROR takes when a positive integer is expected but a negative value is passed in.

Typedefs

typedef unsigned short FR_ERROR
 Fraction error code variable: stores the type of error incurred.

Detailed Description

This file defines error conditions that can result when using Fraction and MFraction classes.

For instance, when the user tries to initilize a fraction object with a denominator of 0, this is not valid and an exception will be thrown of type FR_ERROR with value of FR_DENOM_ZERO. See details below.

Warning:
Error handling for the fraction library is not complete. Particularly, exceptions might be thrown by other operations (implemented in the standard c++ libraries) which are used to implement the fraction operations. These are not caught and taken care of within the fraction class implementation and instead left to the user of the Fraction library. (Use a try-catch block. In most situations, you do not need to worry about errors of this kind.)
Additionally, the Fraction library uses unsigned integers to represent the whole, numerator and denominator parts of a fraction and similar to how unsigned integers have a limitation in their numerical representation, so does objects of type Fraction/MFraction.
I will attempt to tackle and resolve these issues in the later releases of this library. For now, all exceptions which incur are thrown back to the caller of the fraction operations to be caught. (If they are not caught at some point, the program will exit with an error code.) Also, at the moment, the numerical representation limitation issue is ignored. The standard libraries do not pay much attention to this either. (see code block below)
#include "Fraction.h"

int main()
{
        short x;

        cin >> x;       //try a very very large number, the program will not exit with an error code
        cout << x;      //instead, you will get an incorrect result
        std::cin.get();
        return (0);
}

Definition in file FracError.h.


Define Documentation

#define FR_DENOM_ZERO   ((FR_ERROR)1)

A value FR_ERROR takes when a fraction's denominator is equal to 0.

Definition at line 34 of file FracError.h.

#define FR_INDEX_OUT_BOUNDS   ((FR_ERROR)3)

A value FR_ERROR takes when index is out of bounds when using the [] operator to access the private member variables.

See also:
Fraction::operator [] and MFraction::operator []

Definition at line 42 of file FracError.h.

#define FR_NEG_PARAM   ((FR_ERROR)4)

A value FR_ERROR takes when a positive integer is expected but a negative value is passed in.

Definition at line 45 of file FracError.h.

#define FR_STR_INVALID   ((FR_ERROR)2)

A value FR_ERROR takes when a string value can't be converted into a fraction.

Definition at line 37 of file FracError.h.


Typedef Documentation

typedef unsigned short FR_ERROR

Fraction error code variable: stores the type of error incurred.

Definition at line 31 of file FracError.h.