manpagez: man pages & more
info ginac
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.3 Error handling

GiNaC reports run-time errors by throwing C++ exceptions. All exceptions generated by GiNaC are subclassed from the standard exception class defined in the ‘<stdexcept>’ header. In addition to the predefined logic_error, domain_error, out_of_range, invalid_argument, runtime_error, range_error and overflow_error types, GiNaC also defines a pole_error exception that gets thrown when trying to evaluate a mathematical function at a singularity.

The pole_error class has a member function

 
int pole_error::degree() const;

that returns the order of the singularity (or 0 when the pole is logarithmic or the order is undefined).

When using GiNaC it is useful to arrange for exceptions to be caught in the main program even if you don't want to do any special error handling. Otherwise whenever an error occurs in GiNaC, it will be delegated to the default exception handler of your C++ compiler's run-time system which usually only aborts the program without giving any information what went wrong.

Here is an example for a main() function that catches and prints exceptions generated by GiNaC:

 
#include <iostream>
#include <stdexcept>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;

int main()
{
    try {
        ...
        // code using GiNaC
        ...
    } catch (exception &p) {
        cerr << p.what() << endl;
        return 1;
    }
    return 0;
}

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.