Index: ../trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp =================================================================== --- ../trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp (revision 16154) +++ ../trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp (revision 16155) @@ -8,53 +8,71 @@ #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" #endif +#include #include "./exceptions.h" #include "../io/Print/Print.h" #include "../io/Comm/IssmComm.h" -ErrorException::ErrorException(const string &what_arg){/*{{{*/ +ErrorException::ErrorException(const string & what_arg){/*{{{*/ - what_str = what_arg; - file_name = ""; - function_name = ""; + int len; + len = strlen(what_arg.c_str())+1; + what_str = new char[len]; + memcpy(what_str,what_arg.c_str(),len); + + file_name = NULL; + function_name = NULL; file_line = 0; }/*}}}*/ ErrorException::ErrorException(const string& what_file, const string& what_function,int what_line, const string& what_arg){/*{{{*/ - what_str = what_arg; - file_name = what_file; - function_name = what_function; - file_line = what_line; + int len; + len = strlen(what_arg.c_str())+1; + what_str = new char[len]; + memcpy(what_str,what_arg.c_str(),len); + + len = strlen(what_file.c_str())+1; + file_name = new char[len]; + memcpy(file_name,what_file.c_str(),len); + + len = strlen(what_function.c_str())+1; + function_name = new char[len]; + memcpy(function_name,what_function.c_str(),len); + + file_line= what_line; + }/*}}}*/ ErrorException::~ErrorException() throw(){/*{{{*/ + delete [] what_str; + delete [] file_name; + delete [] function_name; }/*}}}*/ const char* ErrorException::what() const throw(){/*{{{*/ - return what_str.c_str(); + return what_str; }/*}}}*/ void ErrorException::Report() const{/*{{{*/ - int my_rank; - int num_procs; + /*WINDOWS*/ + if(!function_name || file_line==0){ + _printf_("Error message: " << what()); + return; + } /*recover my_rank and num_procs:*/ - my_rank=IssmComm::GetRank(); - num_procs=IssmComm::GetSize(); + int my_rank = IssmComm::GetRank(); + int num_procs = IssmComm::GetSize(); - if (function_name=="" || file_line==0){ //WINDOWS - _printf_("Error message: " << what()); + if(num_procs==1){ + _printf_("\n??? Error in ==> " << file_name << ":" << file_line << "\n"); + _printf_(function_name << " error message: " << what() << "\n\n"); } else{ - if(num_procs==1){ - _printf_("\n??? Error in ==> " << file_name.c_str() << ":" << file_line << "\n"); - _printf_(function_name.c_str() << " error message: " << what() << "\n\n"); - } - else{ - _printf_("\n[" << my_rank<< "] ??? Error using ==> " << file_name.c_str() << ":" << file_line << "\n"); - _printf_( "[" << my_rank << "] " << function_name.c_str() << " error message: " << what() << "\n\n"); - } + _printf_("\n[" << my_rank<< "] ??? Error using ==> " << file_name << ":" << file_line << "\n"); + _printf_( "[" << my_rank << "] " << function_name << " error message: " << what() << "\n\n"); } + return; }/*}}}*/ const char* ErrorException::MatlabReport() const{/*{{{*/ @@ -62,14 +80,16 @@ /*Output*/ std::ostringstream buffer; - if (this->file_line==0){ //WINDOWS - buffer << " error message: " << (this->what_str).c_str(); + /*WINDOWS*/ + if(!function_name || file_line==0){ + buffer << " error message: " << this->what_str; + const string buffer2 = buffer.str(); + return buffer2.c_str(); } - else{ - buffer << "\nError in ==> " << (this->file_name).c_str() << ":" << file_line << "\n"; - buffer << (this->function_name).c_str() << " error message: " << (this->what_str).c_str(); - } + buffer << "\nError in ==> " << this->file_name << ":" << file_line << "\n"; + buffer << this->function_name << " error message: " << this->what_str; + const string buffer2 = buffer.str(); return buffer2.c_str(); }/*}}}*/ @@ -78,14 +98,16 @@ /*Output*/ std::ostringstream buffer; - if (this->file_line==0){ //WINDOWS - buffer << " error message: " << (this->what_str).c_str(); + /*WINDOWS*/ + if(!function_name || file_line==0){ + buffer << " error message: " << this->what_str; + const string buffer2 = buffer.str(); + return buffer2.c_str(); } - else{ - buffer << "\nError in ==> " << (this->file_name).c_str() << ":" << file_line << "\n"; - buffer << (this->function_name).c_str() << " error message: " << (this->what_str).c_str(); - } + buffer << "\nError in ==> " << this->file_name << ":" << file_line << "\n"; + buffer << this->function_name << " error message: " << this->what_str; + const string buffer2 = buffer.str(); return buffer2.c_str(); }/*}}}*/ Index: ../trunk-jpl/src/c/shared/Exceptions/exceptions.h =================================================================== --- ../trunk-jpl/src/c/shared/Exceptions/exceptions.h (revision 16154) +++ ../trunk-jpl/src/c/shared/Exceptions/exceptions.h (revision 16155) @@ -75,10 +75,10 @@ /*ISSM exception class: */ class ErrorException: public exception { /*{{{*/ - string what_str; - string function_name; - string file_name; - int file_line; + char* what_str; + char* function_name; + char* file_name; + int file_line; public: ErrorException(const string &what_arg); //for windows