NASA - Jet Propulsion Laboratory
    + View the NASA Portal
Search JPL
Jet Propulsion Laboratory Home Earth Solar System Stars & Galaxies Technology
Introduction Background Software Links

message_error.h

00001 /*
00002  *  This file is part of Healpix_cxx.
00003  *
00004  *  Healpix_cxx 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 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  Healpix_cxx 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 Healpix_cxx; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *  For more information about HEALPix, see http://healpix.jpl.nasa.gov
00019  */
00020 
00021 /*
00022  *  Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
00023  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00024  *  (DLR).
00025  */
00026 
00027 /*
00028  *  Class for error reporting
00029  *
00030  *  Copyright (C) 2003, 2004 Max-Planck-Society
00031  *  Authors: Reinhard Hell, Martin Reinecke
00032  */
00033 
00034 #ifndef PLANCK_MESSAGE_ERROR_H
00035 #define PLANCK_MESSAGE_ERROR_H
00036 
00037 #include <exception>
00038 #include <iostream>
00039 #include <string>
00040 
00041 #if defined (PLANCK_STACKTRACE)
00042 #include <execinfo.h>
00043 #endif
00044 
00045 inline void show_stackframe()
00046   {
00047 #if defined (PLANCK_STACKTRACE)
00048   void *trace[16];
00049   int trace_size = backtrace(trace, 16);
00050   char **messages = backtrace_symbols(trace, trace_size);
00051   std::cerr << "[bt] Execution path:" << std::endl;
00052   for (int i=0; i<trace_size; ++i)
00053     std::cerr << "[bt] " << messages[i] << std::endl;
00054 #endif
00055   }
00056 
00057 
00058 class Message_error
00059   {
00060   private:
00061     std::string msg;
00062 
00063   public:
00064     Message_error()
00065       : msg (std::string("Unspecified error"))
00066       { std::cerr<<msg<<std::endl; show_stackframe(); }
00067 
00068     explicit Message_error(const std::string &message)
00069       : msg (message) { std::cerr<<msg<<std::endl; show_stackframe(); }
00070 
00071     virtual const char* what() const
00072       { return msg.c_str(); }
00073 
00074     virtual ~Message_error() {}
00075   };
00076 
00077 #if defined (PLANCK_CHECKS)
00078 
00079 #define PLANCK_DIAGNOSIS_BEGIN try {
00080 #define PLANCK_DIAGNOSIS_END \
00081 } \
00082 catch (Message_error &e) \
00083   { std::cerr << "Planck exception: " << e.what() << std::endl; throw; } \
00084 catch (std::exception &e) \
00085   { std::cerr << "std::exception: " << e.what() << std::endl; throw; } \
00086 catch (...) \
00087   { std::cerr << "Unknown exception" << std::endl; throw; }
00088 
00089 #else
00090 
00091 #define PLANCK_DIAGNOSIS_BEGIN
00092 #define PLANCK_DIAGNOSIS_END
00093 
00094 #endif
00095 
00096 #endif

Generated on Fri Jun 18 16:12:29 2010 for LevelS C++ support library
Privacy / Copyright
FIRST GOV Contact: NASA Home Page Site Manager:
Webmaster:

CL 03-2650