Error functions — CALCEPH - Octave/Matlab language 3.4.1 documentation

# Error functions

The following group of functions defines the behavior of the library when errors occur during the execution.

## Usage

The following examples, that can be found in the directory examples of the library sources, show the typical usage of this group of functions.

The example in Octave/Matlab language is `mexerror.m`.

The following example shows how to define a custom error handler function.

    %-----------------------------------------------------------------
    % custom error handler
    %-----------------------------------------------------------------
    function myhandler(msg)
        disp('The calceph calls the function myhandler');
        disp('The error message is :')
        disp('----------------------')
        disp(msg)
        disp('----------------------')
        disp('The error handler returns')
    end

    % set the  error handler to use my own callback
    calceph_seterrorhandler(3, 'myhandler')

    % open the ephemeris file
    peph = CalcephBin.open('example1.dat')

## calceph_seterrorhandler

static `calceph_seterrorhandler`(typehandler, userfunc)

  Parameters: | typehandler (int) -- type of handler userfunc (function) -- user function string

This function defines the behavior of the library when an error occurs during the execution of the library's functions. This function should be (not mandatory) called before any other functions of the library. The behavior depends on the value of typehandler.

The possible values for typehandler are :

value | meaning
--- | ---
1 | The library displays a message and continues the execution. The functions return an error code. The python and Octave/Matlab interfaces raise an exception. This is the default behavior of the library.
2 | The library displays a message and terminates the execution with a system call to thefunction exit.
3 | The library calls the user function userfunc with the message.

If the function is called with 1 or 2 for typehandler, the parameter userfunc must be set to an empty string ''.

The function userfunc must be defined as

    function userfunc (msg)
    % parameter msg is of type string
    end