00001 /* 00002 * Copyright (C) 2010 Regents of the University of Michigan 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef __ERROR_HANDLER_H__ 00019 #define __ERROR_HANDLER_H__ 00020 00021 #include <iostream> 00022 00023 class ErrorHandler 00024 { 00025 public: 00026 00027 // This specifies how this class should respond to errors. 00028 // EXCEPTION - throw an exception for the error 00029 // ABORT - exit the program on the error 00030 // RETURN - just return failure on the error. 00031 enum HandlingType {EXCEPTION, ABORT, RETURN}; 00032 00033 // // Type of Error. 00034 // // SUCCESS : method completed successfully. 00035 // // UNKNOWN : unknown result (default value should never be used) 00036 // // FAIL_IO : method failed due to an I/O issue. 00037 // // FAIL_MEM : fail a memory allocation. 00038 // // FAIL_ORDER : method failed because it was called out of order, 00039 // // like trying to read a file without opening it for 00040 // // read or trying to read a record before the header. 00041 // // FAIL_PARSE : failed to parse a record/header - invalid format. 00042 // // INVALID : record is invalid other than for sorting. 00043 // // NO_MORE_RECS : failed to read a record since there are no more to read 00044 // // either in the file or section if section based reading. 00045 // // INVALID_SORT : record is invalid due to it not being sorted. 00046 // enum Type {SUCCESS = 0, UNKNOWN, FAIL_IO, FAIL_MEM, FAIL_ORDER, FAIL_PARSE, 00047 // INVALID, NO_MORE_RECS, INVALID_SORT}; 00048 00049 00050 // Constructor 00051 ErrorHandler(); 00052 00053 // Destructor 00054 ~ErrorHandler(); 00055 00056 // Handle an error based on the error handling type. 00057 static void handleError(const char* message, 00058 HandlingType handlingType = EXCEPTION); 00059 00060 private: 00061 }; 00062 00063 00064 #endif