source:
issm/oecreview/Archive/16133-16554/ISSM-16154-16155.diff
Last change on this file was 16556, checked in by , 11 years ago | |
---|---|
File size: 5.2 KB |
-
../trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp
8 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 9 #endif 10 10 11 #include <cstring> 11 12 #include "./exceptions.h" 12 13 #include "../io/Print/Print.h" 13 14 #include "../io/Comm/IssmComm.h" 14 15 15 ErrorException::ErrorException(const string & what_arg){/*{{{*/16 ErrorException::ErrorException(const string & what_arg){/*{{{*/ 16 17 17 what_str = what_arg; 18 file_name = ""; 19 function_name = ""; 18 int len; 19 len = strlen(what_arg.c_str())+1; 20 what_str = new char[len]; 21 memcpy(what_str,what_arg.c_str(),len); 22 23 file_name = NULL; 24 function_name = NULL; 20 25 file_line = 0; 21 26 22 27 }/*}}}*/ 23 28 ErrorException::ErrorException(const string& what_file, const string& what_function,int what_line, const string& what_arg){/*{{{*/ 24 29 25 what_str = what_arg; 26 file_name = what_file; 27 function_name = what_function; 28 file_line = what_line; 30 int len; 29 31 32 len = strlen(what_arg.c_str())+1; 33 what_str = new char[len]; 34 memcpy(what_str,what_arg.c_str(),len); 35 36 len = strlen(what_file.c_str())+1; 37 file_name = new char[len]; 38 memcpy(file_name,what_file.c_str(),len); 39 40 len = strlen(what_function.c_str())+1; 41 function_name = new char[len]; 42 memcpy(function_name,what_function.c_str(),len); 43 44 file_line= what_line; 45 30 46 }/*}}}*/ 31 47 ErrorException::~ErrorException() throw(){/*{{{*/ 48 delete [] what_str; 49 delete [] file_name; 50 delete [] function_name; 32 51 }/*}}}*/ 33 52 const char* ErrorException::what() const throw(){/*{{{*/ 34 return what_str .c_str();53 return what_str; 35 54 }/*}}}*/ 36 55 void ErrorException::Report() const{/*{{{*/ 37 56 38 int my_rank; 39 int num_procs; 57 /*WINDOWS*/ 58 if(!function_name || file_line==0){ 59 _printf_("Error message: " << what()); 60 return; 61 } 40 62 41 63 /*recover my_rank and num_procs:*/ 42 my_rank=IssmComm::GetRank();43 num_procs=IssmComm::GetSize();64 int my_rank = IssmComm::GetRank(); 65 int num_procs = IssmComm::GetSize(); 44 66 45 if (function_name=="" || file_line==0){ //WINDOWS 46 _printf_("Error message: " << what()); 67 if(num_procs==1){ 68 _printf_("\n??? Error in ==> " << file_name << ":" << file_line << "\n"); 69 _printf_(function_name << " error message: " << what() << "\n\n"); 47 70 } 48 71 else{ 49 if(num_procs==1){ 50 _printf_("\n??? Error in ==> " << file_name.c_str() << ":" << file_line << "\n"); 51 _printf_(function_name.c_str() << " error message: " << what() << "\n\n"); 52 } 53 else{ 54 _printf_("\n[" << my_rank<< "] ??? Error using ==> " << file_name.c_str() << ":" << file_line << "\n"); 55 _printf_( "[" << my_rank << "] " << function_name.c_str() << " error message: " << what() << "\n\n"); 56 } 72 _printf_("\n[" << my_rank<< "] ??? Error using ==> " << file_name << ":" << file_line << "\n"); 73 _printf_( "[" << my_rank << "] " << function_name << " error message: " << what() << "\n\n"); 57 74 } 75 58 76 return; 59 77 }/*}}}*/ 60 78 const char* ErrorException::MatlabReport() const{/*{{{*/ … … 62 80 /*Output*/ 63 81 std::ostringstream buffer; 64 82 65 if (this->file_line==0){ //WINDOWS 66 buffer << " error message: " << (this->what_str).c_str(); 83 /*WINDOWS*/ 84 if(!function_name || file_line==0){ 85 buffer << " error message: " << this->what_str; 86 const string buffer2 = buffer.str(); 87 return buffer2.c_str(); 67 88 } 68 else{69 buffer << "\nError in ==> " << (this->file_name).c_str() << ":" << file_line << "\n";70 buffer << (this->function_name).c_str() << " error message: " << (this->what_str).c_str();71 }72 89 90 buffer << "\nError in ==> " << this->file_name << ":" << file_line << "\n"; 91 buffer << this->function_name << " error message: " << this->what_str; 92 73 93 const string buffer2 = buffer.str(); 74 94 return buffer2.c_str(); 75 95 }/*}}}*/ … … 78 98 /*Output*/ 79 99 std::ostringstream buffer; 80 100 81 if (this->file_line==0){ //WINDOWS 82 buffer << " error message: " << (this->what_str).c_str(); 101 /*WINDOWS*/ 102 if(!function_name || file_line==0){ 103 buffer << " error message: " << this->what_str; 104 const string buffer2 = buffer.str(); 105 return buffer2.c_str(); 83 106 } 84 else{85 buffer << "\nError in ==> " << (this->file_name).c_str() << ":" << file_line << "\n";86 buffer << (this->function_name).c_str() << " error message: " << (this->what_str).c_str();87 }88 107 108 buffer << "\nError in ==> " << this->file_name << ":" << file_line << "\n"; 109 buffer << this->function_name << " error message: " << this->what_str; 110 89 111 const string buffer2 = buffer.str(); 90 112 return buffer2.c_str(); 91 113 }/*}}}*/ -
../trunk-jpl/src/c/shared/Exceptions/exceptions.h
75 75 /*ISSM exception class: */ 76 76 class ErrorException: public exception { /*{{{*/ 77 77 78 stringwhat_str;79 stringfunction_name;80 stringfile_name;81 int 78 char* what_str; 79 char* function_name; 80 char* file_name; 81 int file_line; 82 82 83 83 public: 84 84 ErrorException(const string &what_arg); //for windows
Note:
See TracBrowser
for help on using the repository browser.