Err.pm - Error message 
generator

Further Information 19-Jul-2001


The routines in Err.pm enable error messages to be generated in a uniform style throughout an application. The name of the routine raising the error is obtained from the caller function, and so is correct even if code is moved from one routine to another. Messages may be highlighted to indicate different severity levels.

    Routines return a message string to the user. The string contains no line feed & so may be used with print  or die constructs - 
eg

print "\n".Err::I( "Error test - Information " );
die Err::F( "Error Test - Fatal Error " ) ;

which generate 

Err::Test -I- Error test - Information
Err::TestE -F- Error Test - Fatal Error at Err.pm line 54.

Routines

Routine

Function

Err::D( string ) Generate Debug  message
Err::I( string ) Generate Information message
Err::W( string ) Generate Warning message
Err::E( string ) Generate Error message
Err::F( string ) Generate Fatal Error message
Err::String( string, sev, lvl ) Generate message string at severity sev, identified by routine lvl calls above String.
Err::DbgPrt( string ) Generates a Debug message, and prints it if the variable Err::Debug is defined
Err::Called( string, sev, lvl, up ) As String, but also prints traceback , 1 line for each routine from lvl+1 to up
Err::Trace Prints Traceback

Example

The routine Err::Test tests the functioning of Err:: routines :-

sub Test{
#...     Test routines in Err
#
    print "\n".Err::I( "Error test - Information " );
    print "\n".Err::W( "Error test - Warning     " );
    TestE();
}
sub TestE{
#
    print "\n".Err::E( "Error test - Error       ");
    print "\n".Err::F( "Error test - Fatal       ");
    print "\n".Err::Called( "Error test - called ", "F" , , 1);
#
    print "\n".Err::String( "Error test - String " , "X", 1 );
#
    Err::Trace();
#
    die "\n".Err::F( "Error Test - Fatal Error " ) ;
#
}

& produces this output

Err::Test               -I- Error test - Information
Err::Test               -W- Error test - Warning
Err::TestE              -E- Error test - Error
Err::TestE              -F- Error test - Fatal
Err::TestE              ->> from Err::Test line 42
Err::TestE              -F- Error test - called
Err::TestE              -X- Error test - String
Err::Trace
        0       Err::Trace      52
        1       Err::TestE      42
        2       Err::Test       24
Err::TestE              -F- Error Test - Fatal Error  at Err.pm line 54.