Changeset 26976
- Timestamp:
- 04/29/22 12:09:22 (3 years ago)
- 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 15 15 #include <iomanip> 16 16 #include "./exceptions.h" 17 #include "../io/Print/Print.h"18 #include "../io/Comm/IssmComm.h"19 #include "../MemOps/MemOps.h"20 17 21 18 ErrorException::ErrorException(const string & what_arg){/*{{{*/ … … 31 28 32 29 }/*}}}*/ 33 ErrorException::ErrorException( const string& what_file, const string& what_function,int what_line, const string& what_arg){/*{{{*/30 ErrorException::ErrorException(int what_rank,const string& what_file, const string& what_function,int what_line, const string& what_arg){/*{{{*/ 34 31 32 /*Intermediaries*/ 35 33 int len; 36 34 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; 40 37 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); 44 41 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); 48 45 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); 52 49 50 /*Uncomment if messages do not print properly*/ 51 //this->Report(); 53 52 }/*}}}*/ 54 53 ErrorException::~ErrorException() throw(){/*{{{*/ … … 58 57 }/*}}}*/ 59 58 const char* ErrorException::what() const throw(){/*{{{*/ 60 //this->Report();61 59 return what_str; 62 60 }/*}}}*/ … … 64 62 65 63 /*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; 68 66 return; 69 67 } 70 68 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; 83 71 84 72 return; … … 91 79 92 80 /*WINDOWS*/ 93 if(! function_name ||file_line==0){81 if(!this->function_name || this->file_line==0){ 94 82 buffer << " error message: " << this->what_str; 95 83 } … … 101 89 /*Convert std::ostringstream to std::string and then create char* */ 102 90 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 104 94 return message; 105 95 }/*}}}*/ -
issm/trunk-jpl/src/c/shared/Exceptions/exceptions.h
r24477 r26976 28 28 #include <sstream> 29 29 30 /*macros: */ 30 /*macros: (should move somewhere else)*/ 31 #include "../io/Comm/IssmComm.h" 31 32 /* _assert_ {{{*/ 32 33 /*Assertion macro: do nothing if macro _ISSM_DEBUG_ undefined*/ … … 50 51 do{std::ostringstream aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy; \ 51 52 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) 53 54 #endif 54 55 /*}}}*/ … … 78 79 79 80 /*ISSM exception class: */ 80 class ErrorException: public exception 81 class ErrorException: public exception{ /*{{{*/ 81 82 82 83 char* what_str; … … 84 85 char* file_name; 85 86 int file_line; 87 int rank; 86 88 87 89 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); 90 94 ~ErrorException() throw(); 91 95 virtual const char *what() const throw();
Note:
See TracChangeset
for help on using the changeset viewer.