Changeset 13701


Ignore:
Timestamp:
10/16/12 14:37:32 (12 years ago)
Author:
Mathieu Morlighem
Message:

Better handling of matlab and python errors by putting error message directoy in mexErrTxt
Got rid of c/matlab/io/PrintfFunction.cpp
Initialize IssmComm for modules as -1 so that my_rank and num_proc are still defined

Location:
issm/trunk-jpl/src/c
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/IssmComm.cpp

    r13613 r13701  
    1919}/*}}}*/
    2020int IssmComm::GetRank(){  /*{{{*/
    21         int my_rank;
     21        int my_rank = 0;
     22
     23        /*for matlab and python modules, comm == -1*/
     24        if((int)comm==-1) return my_rank;
     25
    2226        #ifdef _HAVE_MPI_
    2327        MPI_Comm_rank(comm,&my_rank);
    24         #else
    25         my_rank=0;
    2628        #endif
     29
    2730        return my_rank;
    2831
    2932}/*}}}*/
    3033int IssmComm::GetSize(){  /*{{{*/
    31         int size;
     34
     35        int size = 1;
     36
     37        /*for matlab and python modules, comm == -1*/
     38        if((int)comm==-1) return size;
     39
    3240        #ifdef _HAVE_MPI_
    3341        MPI_Comm_size(comm,&size);
    34         #else
    35         size=1;
    3642        #endif
     43
    3744        return size;
    3845
  • issm/trunk-jpl/src/c/include/macros.h

    r13531 r13701  
    2323#define _printf_(flag,...) do{if(flag) PrintfFunction(__VA_ARGS__);}while(0)
    2424/*}}}*/
    25 /* _error2_ {{{*/
     25/* _error_ {{{*/
    2626/*new Error exception macro*/
    2727#ifdef _INTEL_WIN_
     
    8282#define ExceptionTrapEnd(); }\
    8383        catch(ErrorException &exception){\
    84                 exception.Report(); \
    8584                return 1;\
    8685        }\
  • issm/trunk-jpl/src/c/matlab/include/matlab_macros.h

    r13231 r13701  
    2020 * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions
    2121 * will be trapped*/
    22 #define MODULEBOOT(); try{
     22#define MODULEBOOT(); try{ \
     23        IssmComm::SetComm(-1);
    2324
    2425#define MODULEEND(); }\
    2526        catch(ErrorException &exception){\
    26                 mexErrMsgTxt("ISSM Error"); \
     27                mexErrMsgTxt(exception.MatlabReport()); \
    2728        }\
    2829        catch (exception &e){\
  • issm/trunk-jpl/src/c/python/include/python_macros.h

    r13627 r13701  
    2222 * will be trapped*/
    2323#define MODULEBOOT(); \
    24         PyObject *output = PyTuple_New(NLHS);        \
     24        PyObject *output = PyTuple_New(NLHS); \
    2525        int       nrhs   = (int)PyTuple_Size(args);  \
    2626        if(!output) return NULL;\
    27          try{ \
     27        try{ \
     28        IssmComm::SetComm(-1);
    2829
    2930#define MODULEEND(); }\
    3031  catch(ErrorException &exception){\
    31           PyErr_SetString(PyExc_TypeError,"ISSM Error"); \
     32          PyErr_SetString(PyExc_TypeError,exception.PythonReport()); \
    3233          return NULL;\
    3334  } \
  • issm/trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp

    r13622 r13701  
    1212#include "../../include/include.h"
    1313
    14 ErrorException::ErrorException(const string &what_arg){
     14ErrorException::ErrorException(const string &what_arg){/*{{{*/
    1515
    1616        what_str=what_arg;
     
    1818        function_name="";
    1919        file_line=0;
    20 }
    21 
    22 ErrorException::ErrorException(const string& what_file, const string& what_function,int what_line, const string& what_arg){
     20}/*}}}*/
     21ErrorException::ErrorException(const string& what_file, const string& what_function,int what_line, const string& what_arg){/*{{{*/
    2322
    2423        what_str=what_arg;
     
    2625        function_name=what_function;
    2726        file_line=what_line;
    28 }
    29 
    30 ErrorException::~ErrorException() throw(){
    31 
    32         int num_procs;
    33 
    34         /*recover num_procs:*/
    35         num_procs=IssmComm::GetSize();
    36 
    37         /*We want the report only for matlab modules, otherwise we get twice the report
    38          * We assume that if num_procs==1, it is a module (FIXME)*/
    39         if(num_procs==1) this->Report();
    40 }
    41 
    42 const char* ErrorException::what() const throw(){
     27}/*}}}*/
     28ErrorException::~ErrorException() throw(){/*{{{*/
     29}/*}}}*/
     30const char* ErrorException::what() const throw(){/*{{{*/
    4331        return what_str.c_str();
    44 }
    45 
    46 void ErrorException::Report() const{
     32}/*}}}*/
     33void ErrorException::Report() const{/*{{{*/
    4734
    4835        int my_rank;
     
    5845        else{
    5946                if(num_procs==1){
    60                         _printLine_("\n??? Error using ==> " << file_name.c_str() << ":" << file_line);
     47                        _printLine_("\n??? Error in ==> " << file_name.c_str() << ":" << file_line);
    6148                        _printLine_(function_name.c_str() << " error message: " << what() << "\n");
    6249                }
    6350                else{
    6451                        _printLine_("\n[" << my_rank<< "] ??? Error using ==> " << file_name.c_str() << ":" << file_line);
    65                         _printLine_("[" << my_rank << "] " << function_name.c_str() << " error message: " << what() << "\n");
     52                        _printLine_(  "[" << my_rank << "] " << function_name.c_str() << " error message: " << what() << "\n");
    6653                }
    6754        }
    6855        return;
    69 }
     56}/*}}}*/
     57const char* ErrorException::MatlabReport() const{/*{{{*/
     58
     59        /*Output*/
     60        std::ostringstream buffer;
     61
     62        if (this->file_line==0){ //WINDOWS
     63                 buffer << " error message: " << (this->what_str).c_str();
     64        }
     65        else{
     66                buffer << "\nError in ==> " << (this->file_name).c_str() << ":" << file_line << "\n";
     67                buffer << (this->function_name).c_str() << " error message: " << (this->what_str).c_str();
     68        }
     69
     70        return buffer.str().c_str();
     71}/*}}}*/
     72const char* ErrorException::PythonReport() const{/*{{{*/
     73
     74        /*Output*/
     75        std::ostringstream buffer;
     76
     77        if (this->file_line==0){ //WINDOWS
     78                buffer << " error message: " << (this->what_str).c_str();
     79        }
     80        else{
     81                buffer << "\nError in ==> " << (this->file_name).c_str() << ":" << file_line << "\n";
     82                buffer << (this->function_name).c_str() << " error message: " << (this->what_str).c_str();
     83        }
     84
     85        return buffer.str().c_str();
     86}/*}}}*/
  • issm/trunk-jpl/src/c/shared/Exceptions/exceptions.h

    r13623 r13701  
    2828        virtual const char *what() const throw();
    2929        void Report() const;
     30        const char* MatlabReport() const;
     31        const char* PythonReport() const;
    3032
    3133};
Note: See TracChangeset for help on using the changeset viewer.