Matrix Science header

common_error.pl

Generic error handling example.

#!/usr/local/bin/perl
##############################################################################
# file: common_error.pl                                                      #
# 'msparser' toolkit example code                                            #
##############################################################################
# COPYRIGHT NOTICE                                                           #
# Copyright 1998-2010 Matrix Science Limited  All Rights Reserved.           #
#                                                                            #
##############################################################################
#     $Source: /vol/cvsroot/parser/examples/test_perl/common_error.pl,v $ #
#     $Author: davidc $                                                      #
#       $Date: 2016/03/23 15:53:50 $                                         #
#   $Revision: 1.4 $                                                         #
# $NoKeywords::                                                            $ #
##############################################################################
use strict;
##############################################################################

use msparser;

my $file = new msparser::ms_datfile;

$file->setFileName(defined($ARGV[0]) ? $ARGV[0] : 'wrong_name.txt');
$file->read_file();

if ($file->isValid) {
    print "The file has been read and parsed successfully. Congratulations!\n";
} else {
    checkErrorHandler($file);
}


sub checkErrorHandler {
    my ($obj) = @_;

    print "Last error description                   \n";
    print "=========================================\n";
    print "Error: ", $obj->getLastErrorString(), "\n";
    print "=========================================\n";
    print "Testing the error handling...            \n";
    print "=========================================\n";

    my $err = $obj->getErrorHandler();
    my $i;

    for my $i (1 .. $err->getNumberOfErrors) {
        print "Error number: ";
        print $err->getErrorNumber($i);
        print " (";
        print $err->getErrorRepeats($i) + 1;
        print " times) : ";
        print $err->getErrorString($i), "\n";
    }

    print "\n";

    $obj->clearAllErrors();
}



=pod

Running the program with no arguments, for example with

perl -I../bin common_error.pl

will give the output: 


Last error description                   
=========================================
Error: Cannot find Mascot configuration file 'wrong_name.txt'.
=========================================
Testing the error handling...            
=========================================
Error number: 1537 (1 times) : Cannot find Mascot configuration file 'wrong_name.txt'.


=cut

Copyright © 2016 Matrix Science Ltd.  All Rights Reserved. Generated on Fri Jun 2 2017 01:44:50