enzo-dev-problem-types / src / enzo / ErrorExceptions.h

/***********************************************************************
/
/  EXCEPTION CLASS
/
/  written by: Matthew Turk
/  date:       June, 2009
/  modified:   
/
/  PURPOSE:
/
************************************************************************/
#ifndef __ENZO_EXCEPTIONS__
#define __ENZO_EXCEPTIONS__

#ifndef OSX10_4
#include <execinfo.h>
#else
#include "execinfo_local.h"
#endif
#include <signal.h>
#include <stdio.h>

#include <exception>

// If we are using the new problem type initializers, we need to include these
// in a file that we know will be included before macros_and_parameters.h.
#ifdef NEW_PROBLEM_TYPES
#include <stdlib.h>
#include <stdio.h>
#include <map>
#include <string>
#include <vector>
#endif

// Example from 
//
// http://www.ibm.com/developerworks/linux/library/l-cppexcep.html
//

// This must be included BEFORE macros_and_parameters.h
// so we use int here

extern char current_error[255];

 class EnzoFatalException
 {
 public:
     EnzoFatalException(const char *error_msg,
                        const char *filename = NULL,
                        int line_number = 0)
     {
         void * array[25];
         int nSize = backtrace(array, 25);
         char ** symbols = backtrace_symbols(array, nSize);
         fprintf(stderr, "Caught fatal exception:\n\n");
         fprintf(stderr, "   '%s'\n", error_msg);
         if(filename != NULL)
            fprintf(stderr, "at %s:%d\n\n", filename, line_number);
         fprintf(stderr, "Backtrace:\n\n");

         for (int i = 0; i < nSize; i++)
         {
             fprintf(stderr, "BT symbol: %s\n", symbols[i]);
         }

         delete [] symbols;
     }
    void WriteDebuggingOutput()
    {

    }
 };

#endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.