- Timestamp:
- 08/17/09 09:25:19 (15 years ago)
- Location:
- library/bdm/base
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/user_info.cpp
r493 r540 14 14 15 15 namespace bdm { 16 17 string UIException::format_message( const string &reason, const string &path ) { 18 stringstream ss; 19 ss << reason; 20 ss << " Check path \"" << path << "\"."; 21 return ss.str(); 22 } 23 16 24 ///////////////////////////// Class UIFile ///////////////////////////////////////////// 17 25 … … 132 140 133 141 if ( !result->exists ( link ) ) 134 throw UI Exception ( "linked setting was not found", potential_link);142 throw UISettingException ( "UIException: linked setting was not found.", string ( ( const char* ) potential_link ) ); 135 143 136 144 return ( *result ) [link]; … … 145 153 void UI::assert_type ( const Setting &element, Setting::Type type ) { 146 154 if ( element.getType() != type ) 147 throw UI Exception ( "wrong setting type", element );155 throw UISettingException ( "UIException: wrong setting type.", element ); 148 156 } 149 157 150 158 const Setting& UI::to_child_setting ( const Setting &element, const int index ) { 151 159 if ( !element.isList() ) 152 throw UI Exception ( "only TypeList elements could be indexed by integers", element );160 throw UISettingException ( "UIException: only TypeList elements could be indexed by integers.", element ); 153 161 154 162 return element[index]; … … 157 165 const Setting& UI::to_child_setting ( const Setting &element, const string &name ) { 158 166 if ( !element.isGroup() ) 159 throw UI Exception ( "only TypeGroup elements could be indexed by strings", element );167 throw UISettingException ( "UIException: only TypeGroup elements could be indexed by strings.", element ); 160 168 161 169 return element[name]; … … 236 244 const char* elem1 = ( const char* ) link.result[0]; 237 245 if ( ( strcmp ( elem1, "matrix" ) ) ) 238 throw UI Exception ( "the setting supposed to represent a matrix element has wrong syntax", link.result );246 throw UISettingException ( "UIException: the setting supposed to represent a matrix element has wrong syntax.", link.result ); 239 247 240 248 data_offset = 1; 241 249 } else 242 throw UI Exception ( "the setting supposed to represent a matrix element has wrong syntax", link.result );250 throw UISettingException ( "UIException: the setting supposed to represent a matrix element has wrong syntax.", link.result ); 243 251 244 252 Setting &rows_setting = link.result[0 + data_offset]; … … 254 262 255 263 if ( cols < 0 || rows < 0 ) 256 throw UI Exception ( "the dimensions of a matrix has to be non-negative", link.result );264 throw UISettingException ( "UIException: the dimensions of a matrix has to be non-negative.", link.result ); 257 265 258 266 if ( elements.getLength() != cols * rows ) 259 throw UI Exception ( "the count of the matrix elements is incompatible with matrix dimension", elements );267 throw UISettingException ( "UIException: the count of the matrix elements is incompatible with matrix dimension.", elements ); 260 268 261 269 matrix.set_size ( rows, cols ); … … 265 273 266 274 if ( !elements[0].isNumber() ) 267 throw UI Exception ( "matrix elements have to be numbers", elements[0] );275 throw UISettingException ( "UIException: matrix elements have to be numbers.", elements[0] ); 268 276 269 277 // build matrix row-wise … … 275 283 } 276 284 277 throw UI Exception ( "only numeric types or TypeList are supported as matrix values", link.result );285 throw UISettingException ( "UIException: only numeric types or TypeList are supported as matrix values.", link.result ); 278 286 } 279 287 … … 292 300 293 301 if ( matrix.cols() != 1 && matrix.rows() != 1 ) 294 throw UI Exception ( "the vector length is invalid, it seems to be rather a matrix", link.result );302 throw UISettingException ( "UIException: the vector length is invalid, it seems to be rather a matrix.", link.result ); 295 303 296 304 int len = matrix.rows() * matrix.cols(); … … 313 321 314 322 if ( !link.result[0].isNumber() ) 315 throw UI Exception ( "a vector element has to be a number", link.result[0] );323 throw UISettingException ( "UIException: a vector element has to be a number.", link.result[0] ); 316 324 317 325 for ( int i = 0; i < len; i++ ) … … 321 329 } 322 330 323 throw UI Exception ( "only numeric types, TypeArray or TypeList are supported as vector values", link.result );331 throw UISettingException ( "UIException: only numeric types, TypeArray or TypeList are supported as vector values.", link.result ); 324 332 } 325 333 -
library/bdm/base/user_info.h
r535 r540 34 34 namespace bdm { 35 35 36 //! Exception prepared for reporting user-info errors which are always related to some concrete Setting path36 //! Generic exception for reporting configuration errors 37 37 //! 38 38 //! \ref ui_page 39 39 class UIException : public std::exception { 40 41 public: 40 private: 42 41 //! Error message 43 42 const string message; 44 43 45 //! Path to the problematic setting 46 const string path; 47 48 private: 49 string what_message; 50 44 public: 45 /*! 46 \brief The constructor 47 \param message the reason for throwing the exception. Should be a complete English sentence (or a couple sentences), starting with "UIException: ". 48 */ 49 UIException ( const string &message ) : 50 message ( message ) { 51 } 52 53 //! Overriden method for reporting the error message 54 virtual const char* what() const throw() { 55 return message.c_str(); 56 } 57 58 ~UIException() throw() {}; 59 60 protected: 61 /*! 62 Formats error messages for derived classes, which use a 63 Setting path in addition to the message. 64 */ 65 static string format_message( const string &reason, const string &path ); 66 }; 67 68 //! Exception for reporting configuration errors related to some concrete Setting path 69 //! 70 //! \ref ui_page 71 class UISettingException : public UIException { 51 72 public: 52 73 //! Use this constructor when you can pass the problematical Setting as a parameter 53 UIException ( const string &message, const Setting &element ) 54 : message ( "UI error: " + message + "." ), path ( "Check path \"" + string ( element.getPath() ) + "\"." ) { 55 init_what_message(); 74 UISettingException ( const string &message, const Setting &element ): 75 UIException ( format_message ( message, string ( element.getPath() ) ) ) { 56 76 } 57 77 58 78 //! This constructor is for other occasions, when only path of problematical Setting is known 59 UIException ( const string &message, const string &path ) 60 : message ( "UI error: " + message + "." ), path ( "Check path \"" + path + "\"." ) { 61 init_what_message(); 62 } 63 64 //! Overriden method for reporting an error message 65 virtual const char* what() const throw() { 66 return what_message.c_str(); 67 } 68 69 ~UIException() throw() {}; 70 71 private: 72 void init_what_message() { 73 what_message = message; 74 what_message += ' '; 75 what_message += path; 76 } 79 UISettingException ( const string &message, const string &path ): 80 UIException ( format_message ( message, path ) ) { 81 } 82 83 ~UISettingException() throw() {}; 77 84 }; 78 85 86 //! Exception for reporting configuration errors in the "class" attribute 87 //! 88 //! \ref ui_page 89 class UIClassException : public UIException { 90 public: 91 //! Use this constructor when you can pass the problematical Setting as a parameter 92 UIClassException ( const string &message, const Setting &element ): 93 UIException ( format_message ( message, string ( element.getPath() ) ) ) { 94 } 95 96 //! This constructor is for other occasions, when only path of problematical Setting is known 97 UIClassException ( const string &message, const string &path ): 98 UIException ( format_message ( message, path ) ) { 99 } 100 101 ~UIClassException() throw() {}; 102 }; 79 103 80 104 /*! … … 291 315 string class_name; 292 316 if ( !link.result.lookupValue ( "class", class_name ) ) 293 throw UI Exception ( "the obligatory \"class\" identifier is missing", link.result );317 throw UIClassException ( "UIException: the obligatory \"class\" identifier is missing.", link.result ); 294 318 295 319 // then we find a user-info related to this type … … 302 326 if ( !instance ) { 303 327 delete typeless_instance; 304 throw UI Exception ( "class " + class_name + " is not a descendant of the desired output class. Try to call the UI::build<T> function with a different type parameter.", link.result );328 throw UIClassException ( "UIException: class " + class_name + " is not a descendant of the desired output class. Try to call the UI::build<T> function with a different type parameter.", link.result ); 305 329 } 306 330 … … 308 332 instance->from_setting ( link.result ); 309 333 } catch ( SettingException sttng_xcptn ) { 310 string msg = "the method " + class_name + ".from_setting(Setting&) has thrown a SettingException. Try to correct this method. Check path \"" + sttng_xcptn.getPath() + "\"."; 311 throw UIException(msg, link.result); 334 string msg = "UIException: method "; 335 msg += class_name; 336 msg += ".from_setting(Setting&) has thrown a SettingException."; 337 throw UISettingException(msg, sttng_xcptn.getPath()); 312 338 } 313 339 } … … 342 368 //! The exception can help to find the place where the template is misused and also to correct it. 343 369 template<class T> static void from_setting ( T &variable_to_load, const Setting &element ) { 344 std::string msg = " from_setting is not implemented for type ";370 std::string msg = "UIException: from_setting is not implemented for type "; 345 371 msg += typeid(T).name(); 346 throw UIException ( msg, element ); 372 msg += '.'; 373 throw UISettingException ( msg, element ); 347 374 } 348 375 … … 372 399 return shared_ptr<T>(); 373 400 else 374 throw UI Exception ( "the compulsory Setting named \"" + name + "\" is missing", element );401 throw UISettingException ( "UIException: the compulsory Setting named \"" + name + "\" is missing.", element ); 375 402 } 376 403 … … 391 418 stringstream stream; 392 419 stream << index; 393 throw UI Exception ( "the compulsory Setting with the index " + stream.str() + " is missing", element );420 throw UISettingException ( "UIException: the compulsory Setting with the index " + stream.str() + " is missing.", element ); 394 421 } 395 422 } … … 413 440 return false; 414 441 else 415 throw UI Exception ( "the compulsory Setting named \"" + name + "\" is missing", element );442 throw UISettingException ( "UIException: the compulsory Setting named \"" + name + "\" is missing.", element ); 416 443 } 417 444 … … 428 455 else { 429 456 stringstream stream; 457 stream << "UIException: the compulsory Setting with the index " << index << " is missing."; 430 458 stream << index; 431 throw UI Exception ( "the compulsory Setting with the index " + stream.str() + " is missing", element );459 throw UISettingException (stream.str(), element ); 432 460 } 433 461 } … … 494 522 instance->to_setting ( set ); 495 523 } catch ( SettingException sttng_xcptn ) { 496 string msg = "themethod ";497 498 msg += ".to_setting(Setting&) has thrown a SettingException. Try to correct this method.";499 throw UIException(msg, sttng_xcptn.getPath());524 string msg = "UIException: method "; 525 msg += class_name; 526 msg += ".to_setting(Setting&) has thrown a SettingException."; 527 throw UISettingException(msg, sttng_xcptn.getPath()); 500 528 } 501 529 }