Changeset 540 for library/bdm/base/user_info.h
- Timestamp:
- 08/17/09 09:25:19 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
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 }