Changeset 26976


Ignore:
Timestamp:
04/29/22 12:09:22 (3 years ago)
Author:
Mathieu Morlighem
Message:

CHG: removing dependencies between Exceptions and ISSM

Location:
issm/trunk-jpl/src/c/shared/Exceptions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp

    r25293 r26976  
    1515#include <iomanip>
    1616#include "./exceptions.h"
    17 #include "../io/Print/Print.h"
    18 #include "../io/Comm/IssmComm.h"
    19 #include "../MemOps/MemOps.h"
    2017
    2118ErrorException::ErrorException(const string & what_arg){/*{{{*/
     
    3128
    3229}/*}}}*/
    33 ErrorException::ErrorException(const string& what_file, const string& what_function,int what_line, const string& what_arg){/*{{{*/
     30ErrorException::ErrorException(int what_rank,const string& what_file, const string& what_function,int what_line, const string& what_arg){/*{{{*/
    3431
     32        /*Intermediaries*/
    3533        int len;
    3634
    37         len      = strlen(what_arg.c_str())+1;
    38         what_str = new char[len];
    39         memcpy(what_str,what_arg.c_str(),len);
     35        this->rank     = what_rank;
     36        this->file_line= what_line;
    4037
    41         len       = strlen(what_file.c_str())+1;
    42         file_name = new char[len];
    43         memcpy(file_name,what_file.c_str(),len);
     38        len = strlen(what_arg.c_str())+1;
     39        this->what_str = new char[len];
     40        memcpy(this->what_str,what_arg.c_str(),len);
    4441
    45         len           = strlen(what_function.c_str())+1;
    46         function_name = new char[len];
    47         memcpy(function_name,what_function.c_str(),len);
     42        len = strlen(what_file.c_str())+1;
     43        this->file_name = new char[len];
     44        memcpy(this->file_name,what_file.c_str(),len);
    4845
    49         file_line= what_line;
    50         /*When error messages are not shown properly, uncomment the following line*/
    51         this->Report();
     46        len = strlen(what_function.c_str())+1;
     47        this->function_name = new char[len];
     48        memcpy(this->function_name,what_function.c_str(),len);
    5249
     50        /*Uncomment if messages do not print properly*/
     51        //this->Report();
    5352}/*}}}*/
    5453ErrorException::~ErrorException() throw(){/*{{{*/
     
    5857}/*}}}*/
    5958const char* ErrorException::what() const throw(){/*{{{*/
    60         //this->Report();
    6159        return what_str;
    6260}/*}}}*/
     
    6462
    6563        /*WINDOWS*/
    66         if(!function_name || file_line==0){
    67                 _printf_("Error message: " << what());
     64        if(!this->function_name || this->file_line==0){
     65                cerr << "Error message: " << what() << endl;
    6866                return;
    6967        }
    7068
    71         /*recover my_rank and num_procs:*/
    72         int my_rank   = IssmComm::GetRank();
    73         int num_procs = IssmComm::GetSize();
    74 
    75         if(num_procs==1){
    76                 _printf_("\n??? Error in ==> " << file_name << ":" << file_line << "\n");
    77                 _printf_(function_name << " error message: " << what() << "\n\n");
    78         }
    79         else{
    80                 _printf_("\n[" << my_rank<< "] ??? Error using ==> " << file_name << ":" << file_line << "\n");
    81                 _printf_(  "[" << my_rank << "] " << function_name << " error message: " << what() << "\n\n");
    82         }
     69        cerr <<"\n[" << this->rank<< "] ??? Error using ==> " << this->file_name << ":" << this->file_line <<
     70               "\n[" << this->rank<< "] " << this->function_name << " error message: " << what() << "\n" << endl;
    8371
    8472        return;
     
    9179
    9280        /*WINDOWS*/
    93         if(!function_name || file_line==0){
     81        if(!this->function_name || this->file_line==0){
    9482                buffer << " error message: " << this->what_str;
    9583        }
     
    10189        /*Convert std::ostringstream to std::string and then create char* */
    10290        std::string buffer2 = buffer.str();
    103         message = xNew<char>(strlen(buffer2.c_str())+1); sprintf(message,"%s",buffer2.c_str());
     91        message = new char[strlen(buffer2.c_str())+1];
     92        sprintf(message,"%s",buffer2.c_str());
     93
    10494        return message;
    10595}/*}}}*/
  • issm/trunk-jpl/src/c/shared/Exceptions/exceptions.h

    r24477 r26976  
    2828#include <sstream>
    2929
    30 /*macros: */
     30/*macros: (should move somewhere else)*/
     31#include "../io/Comm/IssmComm.h"
    3132/* _assert_ {{{*/
    3233/*Assertion macro: do nothing if macro _ISSM_DEBUG_ undefined*/
     
    5051        do{std::ostringstream aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy; \
    5152   aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy << StreamArgs << std::ends; \
    52    throw ErrorException(__FILE__,__func__,__LINE__,aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy.str());}while(0)
     53   throw ErrorException(IssmComm::GetRank(),__FILE__,__func__,__LINE__,aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy.str());}while(0)
    5354#endif
    5455/*}}}*/
     
    7879
    7980/*ISSM exception class: */
    80 class ErrorException: public exception { /*{{{*/
     81class ErrorException: public exception{ /*{{{*/
    8182
    8283        char* what_str;
     
    8485        char* file_name;
    8586        int   file_line;
     87        int   rank;
    8688
    8789        public:
    88         ErrorException(const string &what_arg); //for windows
    89         ErrorException(const string &what_file,const string& what_function,int what_line,const string& what_arg);//UNIX
     90        /*Windows*/
     91        ErrorException(const string &what_arg);
     92        /*Linux/macOS*/
     93        ErrorException(int what_rank,const string &what_file,const string& what_function,int what_line,const string& what_arg);
    9094        ~ErrorException() throw();
    9195        virtual const char *what() const throw();
Note: See TracChangeset for help on using the changeset viewer.