Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

error.cc

Go to the documentation of this file.
00001 /*
00002 * error.cc Error handling
00003 * Copyright (C) 2000 Arne Schirmacher <arne@schirmacher.de>
00004 * Copyright (C) 2001-2007 Dan Dennedy <dan@dennedy.org>
00005 *
00006 * This program is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU General Public License
00017 * along with this program; if not, write to the Free Software Foundation,
00018 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 // C++ includes
00026 
00027 #include <string>
00028 #include <iostream>
00029 #include <sstream>
00030 #include <iomanip>
00031 
00032 using std::ostringstream;
00033 using std::string;
00034 using std::endl;
00035 using std::ends;
00036 using std::cerr;
00037 
00038 // C includes
00039 
00040 #include <errno.h>
00041 #include <string.h>
00042 
00043 // local includes
00044 
00045 #include "error.h"
00046 
00047 void real_fail_neg( int eval, const char *eval_str, const char *func, const char *file, int line )
00048 {
00049     if ( eval < 0 )
00050     {
00051         string exc;
00052         ostringstream sb;
00053 
00054         sb << file << ":" << line << ": In function \"" << func << "\": \"" << eval_str << "\" evaluated to " << eval;
00055         if ( errno != 0 )
00056             sb << endl << file << ":" << line << ": errno: " << errno << " (" << strerror( errno ) << ")";
00057         sb << ends;
00058         exc = sb.str();
00059         cerr << exc << endl;
00060         throw exc;
00061     }
00062 }
00063 
00064 
00072 void real_fail_null( const void *eval, const char *eval_str, const char *func, const char *file, int line )
00073 {
00074     if ( eval == NULL )
00075     {
00076 
00077         string exc;
00078         ostringstream sb;
00079 
00080         sb << file << ":" << line << ": In function \"" << func << "\": " << eval_str << " is NULL" << ends;
00081         exc = sb.str();
00082         cerr << exc << endl;
00083         throw exc;
00084     }
00085 }
00086 
00087 
00088 void real_fail_if( bool eval, const char *eval_str, const char *func, const char *file, int line )
00089 {
00090     if ( eval == true )
00091     {
00092 
00093         string exc;
00094         ostringstream sb;
00095 
00096         sb << file << ":" << line << ": In function \"" << func << "\": condition \"" << eval_str << "\" is true";
00097         if ( errno != 0 )
00098             sb << endl << file << ":" << line << ": errno: " << errno << " (" << strerror( errno ) << ")";
00099         sb << ends;
00100         exc = sb.str();
00101         cerr << exc << endl;
00102         throw exc;
00103     }
00104 }

Generated on Sun Mar 11 22:11:45 2007 for Kino by  doxygen 1.4.2