Changeset 13363


Ignore:
Timestamp:
09/13/12 13:46:14 (13 years ago)
Author:
Mathieu Morlighem
Message:

NEW: improved error message handle in python

Location:
issm/trunk-jpl/src/c
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/python/include/python_macros.h

    r12365 r13363  
    2020/*The following macros hide the error exception handling in a matlab module. Just put
    2121 * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions
    22  * will be trapped. Really nifty!*/
     22 * will be trapped*/
     23#define MODULEBOOT(); \
     24        PyObject *output = PyTuple_New(NLHS);        \
     25        int       nrhs   = (int)PyTuple_Size(args);  \
     26        if(!output) return NULL;\
     27         try{ \
    2328
    24 #define MODULEBOOT(); ModuleBoot();  \
    25         PyObject* output = PyTuple_New(NLHS); if (!output) return NULL;\
    26                         int nrhs = (int)PyTuple_Size(args);
    27 
    28 #define MODULEEND();  ModuleEnd(); \
    29                                                  return output;
     29#define MODULEEND(); }\
     30  catch(ErrorException &exception){\
     31          PyErr_SetString(PyExc_TypeError,"ISSM Error"); \
     32  } \
     33        catch (exception &e){\
     34                PyErr_SetString(PyExc_TypeError,exprintf("Standard exception: %s\n",e.what()));\
     35        }\
     36        catch(...){\
     37                PyErr_SetString(PyExc_TypeError,"An unexpected error occurred");\
     38        }\
     39        return output;
    3040//}}}
    3141#if _PYTHON_MAJOR_ >=3
  • issm/trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp

    r12520 r13363  
    3939}
    4040
    41 void ErrorException::Report(){
     41void ErrorException::Report() const{
    4242        extern int my_rank;
    4343        extern int num_procs;
  • issm/trunk-jpl/src/c/shared/Exceptions/exceptions.h

    r12479 r13363  
    2727        ~ErrorException() throw();
    2828        virtual const char *what() const throw();
    29         void Report();
     29        void Report() const;
    3030
    3131};
  • issm/trunk-jpl/src/c/shared/TriMesh/TriMeshUtils.cpp

    r13248 r13363  
    255255        int el1,el2;
    256256
    257         double* segments=NULL;
    258         double*    segmentmarkerlist=NULL;
     257        double *segments          = NULL;
     258        double *segmentmarkerlist = NULL;
    259259        int     nsegs;
    260260
    261261        /*Recover input: */
    262         segments=*psegments;
    263         segmentmarkerlist=*psegmentmarkerlist;
    264         nsegs=*pnsegs;
     262        segments          = *psegments;
     263        segmentmarkerlist = *psegmentmarkerlist;
     264        nsegs             = *pnsegs;
    265265
    266266        /*Reallocate segments: */
Note: See TracChangeset for help on using the changeset viewer.