source: issm/oecreview/Archive/16133-16554/ISSM-16154-16155.diff

Last change on this file was 16556, checked in by Mathieu Morlighem, 11 years ago

NEW: added Archive/16133-16554

File size: 5.2 KB
  • ../trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp

     
    88#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
    99#endif
    1010
     11#include <cstring>
    1112#include "./exceptions.h"
    1213#include "../io/Print/Print.h"
    1314#include "../io/Comm/IssmComm.h"
    1415
    15 ErrorException::ErrorException(const string &what_arg){/*{{{*/
     16ErrorException::ErrorException(const string & what_arg){/*{{{*/
    1617
    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;
    2025        file_line     = 0;
    2126
    2227}/*}}}*/
    2328ErrorException::ErrorException(const string& what_file, const string& what_function,int what_line, const string& what_arg){/*{{{*/
    2429
    25         what_str      = what_arg;
    26         file_name     = what_file;
    27         function_name = what_function;
    28         file_line     = what_line;
     30        int len;
    2931
     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
    3046}/*}}}*/
    3147ErrorException::~ErrorException() throw(){/*{{{*/
     48        delete [] what_str;
     49        delete [] file_name;
     50        delete [] function_name;
    3251}/*}}}*/
    3352const char* ErrorException::what() const throw(){/*{{{*/
    34         return what_str.c_str();
     53        return what_str;
    3554}/*}}}*/
    3655void ErrorException::Report() const{/*{{{*/
    3756
    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        }
    4062
    4163        /*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();
    4466
    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");
    4770        }
    4871        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");
    5774        }
     75
    5876        return;
    5977}/*}}}*/
    6078const char* ErrorException::MatlabReport() const{/*{{{*/
     
    6280        /*Output*/
    6381        std::ostringstream buffer;
    6482
    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();
    6788        }
    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         }
    7289
     90        buffer << "\nError in ==> " << this->file_name << ":" << file_line << "\n";
     91        buffer << this->function_name << " error message: " << this->what_str;
     92
    7393        const string buffer2 = buffer.str();
    7494        return buffer2.c_str();
    7595}/*}}}*/
     
    7898        /*Output*/
    7999        std::ostringstream buffer;
    80100
    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();
    83106        }
    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         }
    88107
     108        buffer << "\nError in ==> " << this->file_name << ":" << file_line << "\n";
     109        buffer << this->function_name << " error message: " << this->what_str;
     110
    89111        const string buffer2 = buffer.str();
    90112        return buffer2.c_str();
    91113}/*}}}*/
  • ../trunk-jpl/src/c/shared/Exceptions/exceptions.h

     
    7575/*ISSM exception class: */
    7676class ErrorException: public exception { /*{{{*/
    7777
    78         string  what_str;
    79         string  function_name;
    80         string  file_name;
    81         int      file_line;
     78        char* what_str;
     79        char* function_name;
     80        char* file_name;
     81        int   file_line;
    8282
    8383        public:
    8484        ErrorException(const string &what_arg); //for windows
Note: See TracBrowser for help on using the repository browser.