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

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

NEW: added Archive/16133-16554

File size: 5.2 KB
RevLine 
[16556]1Index: ../trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp
2===================================================================
3--- ../trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp (revision 16154)
4+++ ../trunk-jpl/src/c/shared/Exceptions/Exceptions.cpp (revision 16155)
5@@ -8,53 +8,71 @@
6 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
7 #endif
8
9+#include <cstring>
10 #include "./exceptions.h"
11 #include "../io/Print/Print.h"
12 #include "../io/Comm/IssmComm.h"
13
14-ErrorException::ErrorException(const string &what_arg){/*{{{*/
15+ErrorException::ErrorException(const string & what_arg){/*{{{*/
16
17- what_str = what_arg;
18- file_name = "";
19- function_name = "";
20+ int len;
21+ len = strlen(what_arg.c_str())+1;
22+ what_str = new char[len];
23+ memcpy(what_str,what_arg.c_str(),len);
24+
25+ file_name = NULL;
26+ function_name = NULL;
27 file_line = 0;
28
29 }/*}}}*/
30 ErrorException::ErrorException(const string& what_file, const string& what_function,int what_line, const string& what_arg){/*{{{*/
31
32- what_str = what_arg;
33- file_name = what_file;
34- function_name = what_function;
35- file_line = what_line;
36+ int len;
37
38+ len = strlen(what_arg.c_str())+1;
39+ what_str = new char[len];
40+ memcpy(what_str,what_arg.c_str(),len);
41+
42+ len = strlen(what_file.c_str())+1;
43+ file_name = new char[len];
44+ memcpy(file_name,what_file.c_str(),len);
45+
46+ len = strlen(what_function.c_str())+1;
47+ function_name = new char[len];
48+ memcpy(function_name,what_function.c_str(),len);
49+
50+ file_line= what_line;
51+
52 }/*}}}*/
53 ErrorException::~ErrorException() throw(){/*{{{*/
54+ delete [] what_str;
55+ delete [] file_name;
56+ delete [] function_name;
57 }/*}}}*/
58 const char* ErrorException::what() const throw(){/*{{{*/
59- return what_str.c_str();
60+ return what_str;
61 }/*}}}*/
62 void ErrorException::Report() const{/*{{{*/
63
64- int my_rank;
65- int num_procs;
66+ /*WINDOWS*/
67+ if(!function_name || file_line==0){
68+ _printf_("Error message: " << what());
69+ return;
70+ }
71
72 /*recover my_rank and num_procs:*/
73- my_rank=IssmComm::GetRank();
74- num_procs=IssmComm::GetSize();
75+ int my_rank = IssmComm::GetRank();
76+ int num_procs = IssmComm::GetSize();
77
78- if (function_name=="" || file_line==0){ //WINDOWS
79- _printf_("Error message: " << what());
80+ if(num_procs==1){
81+ _printf_("\n??? Error in ==> " << file_name << ":" << file_line << "\n");
82+ _printf_(function_name << " error message: " << what() << "\n\n");
83 }
84 else{
85- if(num_procs==1){
86- _printf_("\n??? Error in ==> " << file_name.c_str() << ":" << file_line << "\n");
87- _printf_(function_name.c_str() << " error message: " << what() << "\n\n");
88- }
89- else{
90- _printf_("\n[" << my_rank<< "] ??? Error using ==> " << file_name.c_str() << ":" << file_line << "\n");
91- _printf_( "[" << my_rank << "] " << function_name.c_str() << " error message: " << what() << "\n\n");
92- }
93+ _printf_("\n[" << my_rank<< "] ??? Error using ==> " << file_name << ":" << file_line << "\n");
94+ _printf_( "[" << my_rank << "] " << function_name << " error message: " << what() << "\n\n");
95 }
96+
97 return;
98 }/*}}}*/
99 const char* ErrorException::MatlabReport() const{/*{{{*/
100@@ -62,14 +80,16 @@
101 /*Output*/
102 std::ostringstream buffer;
103
104- if (this->file_line==0){ //WINDOWS
105- buffer << " error message: " << (this->what_str).c_str();
106+ /*WINDOWS*/
107+ if(!function_name || file_line==0){
108+ buffer << " error message: " << this->what_str;
109+ const string buffer2 = buffer.str();
110+ return buffer2.c_str();
111 }
112- else{
113- buffer << "\nError in ==> " << (this->file_name).c_str() << ":" << file_line << "\n";
114- buffer << (this->function_name).c_str() << " error message: " << (this->what_str).c_str();
115- }
116
117+ buffer << "\nError in ==> " << this->file_name << ":" << file_line << "\n";
118+ buffer << this->function_name << " error message: " << this->what_str;
119+
120 const string buffer2 = buffer.str();
121 return buffer2.c_str();
122 }/*}}}*/
123@@ -78,14 +98,16 @@
124 /*Output*/
125 std::ostringstream buffer;
126
127- if (this->file_line==0){ //WINDOWS
128- buffer << " error message: " << (this->what_str).c_str();
129+ /*WINDOWS*/
130+ if(!function_name || file_line==0){
131+ buffer << " error message: " << this->what_str;
132+ const string buffer2 = buffer.str();
133+ return buffer2.c_str();
134 }
135- else{
136- buffer << "\nError in ==> " << (this->file_name).c_str() << ":" << file_line << "\n";
137- buffer << (this->function_name).c_str() << " error message: " << (this->what_str).c_str();
138- }
139
140+ buffer << "\nError in ==> " << this->file_name << ":" << file_line << "\n";
141+ buffer << this->function_name << " error message: " << this->what_str;
142+
143 const string buffer2 = buffer.str();
144 return buffer2.c_str();
145 }/*}}}*/
146Index: ../trunk-jpl/src/c/shared/Exceptions/exceptions.h
147===================================================================
148--- ../trunk-jpl/src/c/shared/Exceptions/exceptions.h (revision 16154)
149+++ ../trunk-jpl/src/c/shared/Exceptions/exceptions.h (revision 16155)
150@@ -75,10 +75,10 @@
151 /*ISSM exception class: */
152 class ErrorException: public exception { /*{{{*/
153
154- string what_str;
155- string function_name;
156- string file_name;
157- int file_line;
158+ char* what_str;
159+ char* function_name;
160+ char* file_name;
161+ int file_line;
162
163 public:
164 ErrorException(const string &what_arg); //for windows
Note: See TracBrowser for help on using the repository browser.