Changeset 12078


Ignore:
Timestamp:
04/20/12 13:46:58 (13 years ago)
Author:
Mathieu Morlighem
Message:

Better error handling for matlab modules

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

Legend:

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

    r12022 r12078  
    5757                _printf_(true,"Standard exception: %s\n",e.what());\
    5858                return 1;\
     59        }\
     60        catch(...){\
     61                _printf_(true,"An unexpected error occurred");\
    5962        }
    6063/*}}}*/
  • issm/trunk-jpl/src/c/matlab/include/matlab_macros.h

    r12031 r12078  
    2020 * MODULEBOOT(); and MODULEEND(); at the beginning and end of a module, and c++ exceptions
    2121 * will be trapped. Really nifty!*/
     22//exception.Report();
    2223
    2324#define MODULEBOOT(); ModuleBoot(); \
     
    2627#define MODULEEND(); ModuleEnd(); }\
    2728        catch(ErrorException &exception){\
    28                 exception.Report(); \
    29                 mexErrMsgTxt(""); \
     29                mexErrMsgTxt("ISSM Error"); \
    3030        }\
    31         catch (exception& e) {\
    32                 _printf_(true,"Standard exception: %s\n",e.what());\
    33                 mexErrMsgTxt(" ");\
     31        catch (exception &e){\
     32                mexErrMsgTxt(exprintf("Standard exception: %s\n",e.what()));\
     33        }\
     34        catch(...){\
     35                mexErrMsgTxt("An unexpected error occurred");\
    3436        }
    3537//}}}
  • issm/trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp

    r12018 r12078  
    2929
    3030ErrorException::~ErrorException() throw(){
     31        extern int num_procs;
     32        /*We want the report only for matlab modules, otherwise we get twice the report
     33         * We assume that if num_procs==1, it is a module (FIXME)*/
     34        if(num_procs==1) this->Report();
    3135}
    3236
     
    3741void ErrorException::Report(){
    3842        extern int my_rank;
     43        extern int num_procs;
    3944
    4045        if (function_name=="" || file_line==0){ //WINDOWS
     
    4247        }
    4348        else{
    44                 printf("\n[%i] ??? Error using ==> %s:%i\n",my_rank,file_name.c_str(),file_line);
    45                 printf("[%i] %s error message: %s\n\n",my_rank,function_name.c_str(),what());
     49                if(num_procs==1){
     50                        printf("\n??? Error using ==> %s:%i\n",file_name.c_str(),file_line);
     51                        printf("%s error message: %s\n\n",function_name.c_str(),what());
     52                }
     53                else{
     54                        printf("\n[%i] ??? Error using ==> %s:%i\n",my_rank,file_name.c_str(),file_line);
     55                        printf("[%i] %s error message: %s\n\n",my_rank,function_name.c_str(),what());
     56                }
    4657        }
    4758        return;
  • issm/trunk-jpl/src/c/shared/Exceptions/exceptions.h

    r11199 r12078  
    1717class ErrorException: public exception {
    1818       
     19        public:
     20
    1921        string   what_str;
    2022        string   function_name;
     
    2224        int      file_line;
    2325
    24         public:
    2526
    2627        ErrorException(const string &what_arg); //for windows
    2728        ErrorException(string what_file,string what_function,int what_line,string what_arg);//UNIX
    2829        ~ErrorException() throw();
    29 
    3030        virtual const char *what() const throw();
    31 
    3231        void Report();
    3332
Note: See TracChangeset for help on using the changeset viewer.