libyui
3.0.10
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: YUIException.h 00020 00021 Stolen from zypp/libzypp/base/Exception.h 00022 00023 Author: Michael Andres <ma@suse.de> 00024 Maintainer: Stefan Hundhammer <sh@suse.de> 00025 00026 /-*/ 00027 00028 #ifndef YUIException_h 00029 #define YUIException_h 00030 00031 00032 #include <cerrno> 00033 #include <iostream> 00034 #include <stdexcept> 00035 00036 #include "YProperty.h" 00037 00038 00039 class YWidget; 00040 00041 00042 // 00043 // Macros for application use 00044 // 00045 00046 /** 00047 * Usage summary: 00048 * 00049 * Use YUI_THROW to throw exceptions. 00050 * Use YUI_CAUGHT If you caught an exceptions in order to handle it. 00051 * Use YUI_RETHROW to rethrow a caught exception. 00052 * 00053 * The use of these macros is not mandatory. but YUI_THROW and YUI_RETHROW will 00054 * adjust the code location information stored in the exception. All three 00055 * macros will drop a line in the log file. 00056 * 00057 * 43 try 00058 * 44 { 00059 * 45 try 00060 * 46 { 00061 * 47 YUI_THROW( YUIException("Something bad happened.") ); 00062 * 48 } 00063 * 49 catch( YUIException & exception ) 00064 * 50 { 00065 * 51 YUI_RETHROW( exception ); 00066 * 52 } 00067 * 53 } 00068 * 54 catch( YUIException & exception ) 00069 * 55 { 00070 * 56 YUI_CAUGHT( exception ); 00071 * 57 } 00072 * 00073 * The above produces the following log lines: 00074 * 00075 * Main.cc(main):47 THROW: Main.cc(main):47: Something bad happened. 00076 * Main.cc(main):51 RETHROW: Main.cc(main):47: Something bad happened. 00077 * Main.cc(main):56 CAUGHT: Main.cc(main):51: Something bad happened. 00078 **/ 00079 00080 00081 /** 00082 * Create YCodeLocation object storing the current location. 00083 **/ 00084 #define YUI_EXCEPTION_CODE_LOCATION YCodeLocation(__FILE__,__FUNCTION__,__LINE__) 00085 00086 00087 /** 00088 * Drops a log line and throws the YUIException. 00089 **/ 00090 #define YUI_THROW( EXCEPTION ) \ 00091 _YUI_THROW( ( EXCEPTION ), YUI_EXCEPTION_CODE_LOCATION ) 00092 00093 /** 00094 * Drops a log line telling the YUIException was caught and handled. 00095 **/ 00096 #define YUI_CAUGHT( EXCEPTION ) \ 00097 _YUI_CAUGHT( ( EXCEPTION ), YUI_EXCEPTION_CODE_LOCATION ) 00098 00099 00100 /** 00101 * Drops a log line and rethrows, updating the YCodeLocation. 00102 **/ 00103 #define YUI_RETHROW( EXCEPTION ) \ 00104 _YUI_RETHROW( ( EXCEPTION ), YUI_EXCEPTION_CODE_LOCATION ) 00105 00106 00107 /** 00108 * Throw YUIException built from a message string. 00109 **/ 00110 #define YUI_THROW_MSG( EXCEPTION_TYPE, MSG ) \ 00111 YUI_THROW( EXCEPTION_TYPE( MSG ) ) 00112 00113 00114 /** 00115 * Throw YUIException built from errno. 00116 **/ 00117 #define YUI_THROW_ERRNO( EXCEPTION_TYPE ) \ 00118 YUI_THROW( EXCEPTION_TYPE( YUIException::strErrno( errno ) ) ) 00119 00120 /** 00121 * Throw YUIException built from errno provided as argument. 00122 **/ 00123 #define YUI_THROW_ERRNO1( EXCEPTION_TYPE, ERRNO ) \ 00124 YUI_THROW( EXCEPTION_TYPE( YUIException::strErrno( ERRNO ) ) ) 00125 00126 /** 00127 * Throw YUIException built from errno and a message string. 00128 **/ 00129 #define YUI_THROW_ERRNO_MSG( EXCEPTION_TYPE, MSG) \ 00130 YUI_THROW( EXCEPTION_TYPE( YUIException::strErrno( errno, MSG ) ) ) 00131 00132 /** 00133 * Throw YUIException built from errno provided as argument and a message string. 00134 **/ 00135 #define YUI_THROW_ERRNO_MSG1( EXCEPTION_TYPE, ERRNO,MSG ) \ 00136 YUI_THROW( EXCEPTION_TYPE( YUIException::strErrno( ERRNO, MSG ) ) ) 00137 00138 00139 // 00140 // Higher-level (UI specific) exception macros 00141 // 00142 00143 /** 00144 * Check if an instance returned by operator new is valid (nonzero). 00145 * Throws YUIOutOfMemoryException if it is 0. 00146 **/ 00147 #define YUI_CHECK_NEW( PTR ) \ 00148 do \ 00149 { \ 00150 if ( ! (PTR) ) \ 00151 { \ 00152 YUI_THROW( YUIOutOfMemoryException() ); \ 00153 } \ 00154 } while( 0 ) 00155 00156 00157 00158 /** 00159 * Check for null pointer. 00160 * Throws YUINullPointerException if the pointer is 0. 00161 **/ 00162 #define YUI_CHECK_PTR( PTR ) \ 00163 do \ 00164 { \ 00165 if ( ! (PTR) ) \ 00166 { \ 00167 YUI_THROW( YUINullPointerException() ); \ 00168 } \ 00169 } while( 0 ) 00170 00171 00172 /** 00173 * Check if a widget pointer is valid. 00174 * Throws YUIInvalidWidgetException if it is 0 or invalid (already deleted). 00175 **/ 00176 #define YUI_CHECK_WIDGET( WIDGET ) \ 00177 do \ 00178 { \ 00179 if ( ! (WIDGET) || ! (WIDGET)->isValid() ) \ 00180 { \ 00181 YUI_THROW( YUIInvalidWidgetException() ); \ 00182 } \ 00183 } while( 0 ) 00184 00185 00186 /** 00187 * Check if an index is in range: 00188 * VALID_MIN <= INDEX <= VALID_MAX 00189 * 00190 * Throws YUIInvalidWidgetException if out of range. 00191 **/ 00192 #define YUI_CHECK_INDEX_MSG( INDEX, VALID_MIN, VALID_MAX, MSG ) \ 00193 do \ 00194 { \ 00195 if ( (INDEX) < (VALID_MIN) || \ 00196 (INDEX) > (VALID_MAX) ) \ 00197 { \ 00198 YUI_THROW( YUIIndexOutOfRangeException( (INDEX), (VALID_MIN), (VALID_MAX), (MSG) ) ); \ 00199 } \ 00200 } while( 0 ) 00201 00202 00203 #define YUI_CHECK_INDEX( INDEX, VALID_MIN, VALID_MAX ) \ 00204 YUI_CHECK_INDEX_MSG( (INDEX), (VALID_MIN), (VALID_MAX), "") 00205 00206 00207 00208 00209 /** 00210 * Helper class for UI exceptions: Store _FILE_, _FUNCTION_ and _LINE_. 00211 * Construct this using the YUI_EXCEPTION_CODE_LOCATION macro. 00212 **/ 00213 class YCodeLocation 00214 { 00215 public: 00216 /** 00217 * Constructor. 00218 * Commonly called using the YUI_EXCEPTION_CODE_LOCATION macro. 00219 **/ 00220 YCodeLocation( const std::string & file_r, 00221 const std::string & func_r, 00222 int line_r ) 00223 : _file( file_r ) 00224 , _func( func_r ) 00225 , _line( line_r ) 00226 {} 00227 00228 /** 00229 * Default constructor. 00230 ***/ 00231 YCodeLocation() 00232 : _line( 0 ) 00233 {} 00234 00235 /** 00236 * Returns the source file name where the exception occured. 00237 **/ 00238 std::string file() const { return _file; } 00239 00240 /** 00241 * Returns the name of the function where the exception occured. 00242 **/ 00243 std::string func() const { return _func; } 00244 00245 /** 00246 * Returns the source line number where the exception occured. 00247 **/ 00248 int line() const { return _line; } 00249 00250 /** 00251 * Returns the location in normalized string format. 00252 **/ 00253 std::string asString() const; 00254 00255 /** 00256 * Stream output 00257 **/ 00258 friend std::ostream & operator<<( std::ostream & str, const YCodeLocation & obj ); 00259 00260 private: 00261 std::string _file; 00262 std::string _func; 00263 int _line; 00264 00265 }; // YCodeLocation 00266 00267 00268 /** 00269 * YCodeLocation stream output 00270 **/ 00271 std::ostream & operator<<( std::ostream & str, const YCodeLocation & obj ); 00272 00273 00274 /** 00275 * Base class for UI Exceptions. 00276 * 00277 * Exception offers to store a message string passed to the constructor. 00278 * Derived classes may provide additional information. 00279 * Overload dumpOn to provide a proper error text. 00280 **/ 00281 class YUIException : public std::exception 00282 { 00283 public: 00284 /** 00285 * Default constructor. 00286 * Use YUI_THROW to throw exceptions. 00287 **/ 00288 YUIException(); 00289 00290 /** 00291 * Constructor taking a message. 00292 * Use YUI_THROW to throw exceptions. 00293 **/ 00294 YUIException( const std::string & msg_r ); 00295 00296 /** 00297 * Destructor. 00298 **/ 00299 virtual ~YUIException() throw(); 00300 00301 /** 00302 * Return YCodeLocation. 00303 **/ 00304 const YCodeLocation & where() const 00305 { return _where; } 00306 00307 /** 00308 * Exchange location on rethrow. 00309 **/ 00310 void relocate( const YCodeLocation & newLocation ) const 00311 { _where = newLocation; } 00312 00313 /** 00314 * Return the message string provided to the constructor. 00315 * Note: This is not neccessarily the complete error message. 00316 * The whole error message is provided by asString or dumpOn. 00317 **/ 00318 const std::string & msg() const 00319 { return _msg; } 00320 00321 /** 00322 * Set a new message string. 00323 **/ 00324 void setMsg( const std::string & msg ) 00325 { _msg = msg; } 00326 00327 /** 00328 * Error message provided by dumpOn as string. 00329 **/ 00330 std::string asString() const; 00331 00332 /** 00333 * Make a string from errno_r. 00334 **/ 00335 static std::string strErrno( int errno_r ); 00336 00337 /** 00338 * Make a string from errno_r and msg_r. 00339 **/ 00340 static std::string strErrno( int errno_r, const std::string & msg ); 00341 00342 /** 00343 * Drop a log line on throw, catch or rethrow. 00344 * Used by YUI_THROW macros. 00345 **/ 00346 static void log( const YUIException & exception, 00347 const YCodeLocation & location, 00348 const char * const prefix ); 00349 /** 00350 * Return message string. 00351 * 00352 * Reimplemented from std::exception. 00353 **/ 00354 virtual const char * what() const throw() 00355 { return _msg.c_str(); } 00356 00357 protected: 00358 00359 /** 00360 * Overload this to print a proper error message. 00361 **/ 00362 virtual std::ostream & dumpOn( std::ostream & str ) const; 00363 00364 00365 private: 00366 friend std::ostream & operator<<( std::ostream & str, const YUIException & obj ); 00367 00368 00369 mutable YCodeLocation _where; 00370 std::string _msg; 00371 00372 /** 00373 * Called by std::ostream & operator<<() . 00374 * Prints YCodeLocation and the error message provided by dumpOn. 00375 **/ 00376 std::ostream & dumpError( std::ostream & str ) const; 00377 00378 }; // class YUIException 00379 00380 00381 /** 00382 * YUIException stream output 00383 **/ 00384 std::ostream & operator<<( std::ostream & str, const YUIException & obj ); 00385 00386 00387 /** 00388 * Exception class for generic null pointer exceptions. 00389 * When available, a more specialized exception class should be used. 00390 **/ 00391 class YUINullPointerException: public YUIException 00392 { 00393 public: 00394 YUINullPointerException() 00395 : YUIException( "Null pointer" ) 00396 {} 00397 00398 virtual ~YUINullPointerException() throw() 00399 {} 00400 }; 00401 00402 00403 /** 00404 * Exception class for "out of memory". 00405 * Typically used if operator new returned 0. 00406 **/ 00407 class YUIOutOfMemoryException: public YUIException 00408 { 00409 public: 00410 YUIOutOfMemoryException() 00411 : YUIException( "Out of memory" ) 00412 {} 00413 00414 virtual ~YUIOutOfMemoryException() throw() 00415 {} 00416 00417 }; 00418 00419 /** 00420 * Exception class for invalid widgets. 00421 * This is typically caused by widget pointers that continue living after the 00422 * corresponding widget has already been deleted. 00423 **/ 00424 class YUIInvalidWidgetException: public YUIException 00425 { 00426 public: 00427 YUIInvalidWidgetException() 00428 : YUIException( "Invalid widget" ) 00429 {} 00430 00431 virtual ~YUIInvalidWidgetException() throw() 00432 {} 00433 }; 00434 00435 00436 /** 00437 * Exception class for "No widget found with that ID". 00438 **/ 00439 class YUIWidgetNotFoundException: public YUIException 00440 { 00441 public: 00442 YUIWidgetNotFoundException( const std::string & idString ) 00443 : YUIException( std::string( "No widget with ID " ) + idString ) 00444 {} 00445 00446 virtual ~YUIWidgetNotFoundException() throw() 00447 {} 00448 }; 00449 00450 00451 class YUINoDialogException: public YUIException 00452 { 00453 public: 00454 YUINoDialogException() 00455 : YUIException( "No dialog existing" ) 00456 {} 00457 00458 virtual ~YUINoDialogException() throw() 00459 {} 00460 }; 00461 00462 00463 class YUIDialogStackingOrderException: public YUIException 00464 { 00465 public: 00466 YUIDialogStackingOrderException() 00467 : YUIException( "Dialog stacking order violated" ) 00468 {} 00469 00470 virtual ~YUIDialogStackingOrderException() throw() 00471 {} 00472 }; 00473 00474 00475 class YUISyntaxErrorException: public YUIException 00476 { 00477 public: 00478 YUISyntaxErrorException( const std::string & msg ) 00479 : YUIException( msg ) 00480 {} 00481 00482 virtual ~YUISyntaxErrorException() throw() 00483 {} 00484 }; 00485 00486 00487 /** 00488 * Abstract base class for widget property exceptions. 00489 **/ 00490 class YUIPropertyException: public YUIException 00491 { 00492 protected: 00493 YUIPropertyException( const YProperty & prop, 00494 YWidget * widget = 0 ) 00495 : YUIException() 00496 , _property( prop ) 00497 , _widget( widget ) 00498 {} 00499 00500 virtual ~YUIPropertyException() throw() 00501 {} 00502 00503 public: 00504 /** 00505 * Returns the property that caused this exception. 00506 **/ 00507 YProperty property() const { return _property; } 00508 00509 /** 00510 * Returns the corresponding widget or 0 if there was none. 00511 **/ 00512 YWidget * widget() const { return _widget; } 00513 00514 /** 00515 * Set the corresponding widget. 00516 **/ 00517 void setWidget( YWidget * w ) { _widget = w; } 00518 00519 protected: 00520 00521 /** 00522 * Write proper error message with all relevant data. 00523 * Reimplemented from YUIException. 00524 **/ 00525 virtual std::ostream & dumpOn( std::ostream & str ) const = 0; 00526 00527 private: 00528 YProperty _property; 00529 YWidget * _widget; 00530 }; 00531 00532 00533 /** 00534 * Exception class for "unknown property name": 00535 * The application tried to set (or query) a property that doesn't exist. 00536 **/ 00537 class YUIUnknownPropertyException: public YUIPropertyException 00538 { 00539 public: 00540 YUIUnknownPropertyException( const std::string & propertyName, 00541 YWidget * widget = 0 ) 00542 : YUIPropertyException( YProperty( propertyName, YUnknownPropertyType ), widget ) 00543 {} 00544 00545 virtual ~YUIUnknownPropertyException() throw() 00546 {} 00547 00548 protected: 00549 00550 /** 00551 * Write proper error message with all relevant data. 00552 * Reimplemented from YUIException. 00553 **/ 00554 virtual std::ostream & dumpOn( std::ostream & str ) const; 00555 }; 00556 00557 00558 /** 00559 * Exception class for "property type mismatch": 00560 * The application tried to set a property with a wrong type. 00561 **/ 00562 class YUIPropertyTypeMismatchException: public YUIPropertyException 00563 { 00564 public: 00565 00566 YUIPropertyTypeMismatchException( const YProperty & property, 00567 YPropertyType type, 00568 YWidget * widget = 0 ) 00569 : YUIPropertyException( property, widget ) 00570 , _type( type ) 00571 {} 00572 00573 virtual ~YUIPropertyTypeMismatchException() throw() 00574 {} 00575 00576 /** 00577 * Return the property type the application tried to set. 00578 **/ 00579 YPropertyType type() const { return _type; } 00580 00581 protected: 00582 00583 /** 00584 * Write proper error message with all relevant data. 00585 * Reimplemented from YUIException. 00586 **/ 00587 virtual std::ostream & dumpOn( std::ostream & str ) const; 00588 00589 private: 00590 YPropertyType _type; 00591 }; 00592 00593 00594 /** 00595 * Exception class for attempt to set a read-only property. 00596 **/ 00597 class YUISetReadOnlyPropertyException: public YUIPropertyException 00598 { 00599 public: 00600 00601 YUISetReadOnlyPropertyException( const YProperty & property, 00602 YWidget * widget = 0 ) 00603 : YUIPropertyException( property, widget ) 00604 {} 00605 00606 virtual ~YUISetReadOnlyPropertyException() throw() 00607 {} 00608 00609 protected: 00610 00611 /** 00612 * Write proper error message with all relevant data. 00613 * Reimplemented from YUIException. 00614 **/ 00615 virtual std::ostream & dumpOn( std::ostream & str ) const; 00616 }; 00617 00618 00619 class YUIBadPropertyArgException: public YUIPropertyException 00620 { 00621 public: 00622 00623 YUIBadPropertyArgException( const YProperty & property, 00624 YWidget * widget, 00625 const std::string & message = "" ) 00626 : YUIPropertyException( property, widget ) 00627 { setMsg( message ); } 00628 00629 virtual ~YUIBadPropertyArgException() throw() 00630 {} 00631 00632 protected: 00633 00634 /** 00635 * Write proper error message with all relevant data. 00636 * Reimplemented from YUIException. 00637 **/ 00638 virtual std::ostream & dumpOn( std::ostream & str ) const; 00639 }; 00640 00641 00642 /** 00643 * Exception class for "too many children": 00644 * Attempt to add a child to a widget class that can't handle children 00645 * (YPushButton etc.) or just one child (YFrame, YDialog). 00646 **/ 00647 template<class YWidget> class YUITooManyChildrenException: public YUIException 00648 { 00649 public: 00650 00651 YUITooManyChildrenException( YWidget * container ) 00652 : YUIException( "Too many children" ) 00653 , _container( container ) 00654 {} 00655 00656 virtual ~YUITooManyChildrenException() throw() 00657 {} 00658 00659 /** 00660 * Returns the container widget that can't handle that many children. 00661 **/ 00662 YWidget * container() const { return _container; } 00663 00664 protected: 00665 00666 /** 00667 * Write proper error message with all relevant data. 00668 * Reimplemented from YUIException. 00669 **/ 00670 virtual std::ostream & dumpOn( std::ostream & str ) const 00671 { 00672 std::string widgetClass = 00673 container() ? container()->widgetClass() : 00674 "widget"; 00675 00676 return str << "Too many children for " 00677 << widgetClass 00678 << std::endl; 00679 } 00680 00681 private: 00682 00683 YWidget * _container; 00684 }; 00685 00686 00687 /** 00688 * Exception class for "invalid child". One of: 00689 * 00690 * - Attempt to remove a child from a children manager that is not in that 00691 * manager's children list. 00692 * 00693 * - Child widget of wrong type added to a container widget, e.g., anything 00694 * other than a YPushButton added to a YButtonBox. 00695 **/ 00696 template<class YWidget> class YUIInvalidChildException: public YUIException 00697 { 00698 public: 00699 00700 YUIInvalidChildException( YWidget * container, 00701 YWidget * child = 0 ) 00702 : YUIException( "Invalid child" ) 00703 , _container( container ) 00704 , _child( child ) 00705 {} 00706 00707 virtual ~YUIInvalidChildException() throw() 00708 {} 00709 00710 /** 00711 * Returns the container widget whose child should be removed etc. 00712 **/ 00713 YWidget * container() const { return _container; } 00714 00715 /** 00716 * Returns the child widget. 00717 **/ 00718 YWidget * child() const { return _child; } 00719 00720 protected: 00721 00722 /** 00723 * Write proper error message with all relevant data. 00724 * Reimplemented from YUIException. 00725 **/ 00726 virtual std::ostream & dumpOn( std::ostream & str ) const 00727 { 00728 std::string containerWidgetClass = 00729 container() ? container()->widgetClass() : 00730 "widget"; 00731 00732 std::string childWidgetClass = 00733 child() ? child()->widgetClass() : 00734 "<Null>"; 00735 00736 return str << childWidgetClass 00737 << " is not a child of " 00738 << containerWidgetClass 00739 << std::endl; 00740 } 00741 00742 private: 00743 00744 YWidget * _container; 00745 YWidget * _child; 00746 }; 00747 00748 00749 00750 /** 00751 * Exception class for "optional widget not supported". 00752 * 00753 * Note that applications are supposed to check with 00754 * YUI::optionalWidgetFactory()->hasXYWidget() before trying to create such a 00755 * widget. This exception is thrown if that check wasn't done, the application 00756 * tried to create that kind of widget anyway, but the UI doesn't support that 00757 * widget. 00758 **/ 00759 class YUIUnsupportedWidgetException: public YUIException 00760 { 00761 public: 00762 00763 YUIUnsupportedWidgetException( const std::string & widgetType ) 00764 : YUIException( std::string( "Unsupported optional widget type: " ) + widgetType ) 00765 {} 00766 00767 virtual ~YUIUnsupportedWidgetException() throw() 00768 {} 00769 }; 00770 00771 00772 /** 00773 * Exception class for "value other than YD_HORIZ or YD_VERT used for 00774 * dimension". 00775 **/ 00776 class YUIInvalidDimensionException: public YUIException 00777 { 00778 public: 00779 YUIInvalidDimensionException() 00780 : YUIException( "Invalid dimension (neither YD_HORIZ nor YD_VERT)" ) 00781 {} 00782 00783 virtual ~YUIInvalidDimensionException() throw() 00784 {} 00785 }; 00786 00787 00788 /** 00789 * Exception class for "index out of range" 00790 **/ 00791 class YUIIndexOutOfRangeException: public YUIException 00792 { 00793 public: 00794 /** 00795 * Constructor. 00796 * 00797 * 'invalidIndex' is the offending index value. It should be between 00798 *'validMin' and 'validMax': 00799 * 00800 * validMin <= index <= validMax 00801 **/ 00802 YUIIndexOutOfRangeException( int invalidIndex, 00803 int validMin, 00804 int validMax, 00805 const std::string & msg = "" ) 00806 : YUIException( msg ) 00807 , _invalidIndex( invalidIndex ) 00808 , _validMin( validMin ) 00809 , _validMax( validMax ) 00810 {} 00811 00812 virtual ~YUIIndexOutOfRangeException() throw() 00813 {} 00814 00815 /** 00816 * Return the offending index value. 00817 **/ 00818 int invalidIndex() const { return _invalidIndex; } 00819 00820 /** 00821 * Return the valid minimum index. 00822 **/ 00823 int validMin() const { return _validMin; } 00824 00825 /** 00826 * Return the valid maximum index. 00827 **/ 00828 int validMax() const { return _validMax; } 00829 00830 protected: 00831 00832 /** 00833 * Write proper error message with all relevant data. 00834 * Reimplemented from YUIException. 00835 **/ 00836 virtual std::ostream & dumpOn( std::ostream & str ) const 00837 { 00838 std::string prefix = msg(); 00839 00840 if ( prefix.empty() ) 00841 prefix = "Index out of range"; 00842 00843 return str << prefix << ": " << _invalidIndex 00844 << " valid: " << _validMin << " .. " << _validMax 00845 << std::endl; 00846 } 00847 00848 private: 00849 00850 int _invalidIndex; 00851 int _validMin; 00852 int _validMax; 00853 }; 00854 00855 00856 /** 00857 * Exception class for plugin load failure 00858 **/ 00859 class YUIPluginException: public YUIException 00860 { 00861 public: 00862 YUIPluginException( const std::string & pluginName ) 00863 : YUIException( std::string( "Couldn't load plug-in " ) + pluginName ) 00864 {} 00865 00866 virtual ~YUIPluginException() throw() 00867 {} 00868 }; 00869 00870 00871 /** 00872 * Exception class for UI plugin load failure 00873 **/ 00874 class YUICantLoadAnyUIException: public YUIException 00875 { 00876 public: 00877 YUICantLoadAnyUIException() 00878 : YUIException( "No $DISPLAY and stdout is not a tty" ) 00879 {} 00880 00881 virtual ~YUICantLoadAnyUIException() throw() 00882 {} 00883 }; 00884 00885 00886 /** 00887 * Exception class for "wrong button roles in YButtonBox" 00888 **/ 00889 class YUIButtonRoleMismatchException: public YUIException 00890 { 00891 public: 00892 00893 YUIButtonRoleMismatchException( const std::string & msg ) 00894 : YUIException( msg ) 00895 {} 00896 00897 virtual ~YUIButtonRoleMismatchException() throw() 00898 {} 00899 }; 00900 00901 00902 // 00903 // Helper templates 00904 // 00905 00906 00907 /** 00908 * Helper for YUI_THROW() 00909 **/ 00910 template<class _Exception> 00911 void _YUI_THROW( const _Exception & exception_r, const YCodeLocation & where_r ) 00912 { 00913 exception_r.relocate( where_r ); 00914 YUIException::log( exception_r, where_r, "THROW: " ); 00915 throw( exception_r ); 00916 } 00917 00918 00919 /** 00920 * Helper for YUI_CAUGHT() 00921 **/ 00922 template<class _Exception> 00923 void _YUI_CAUGHT( const _Exception & exception_r, const YCodeLocation & where_r ) 00924 { 00925 YUIException::log( exception_r, where_r, "CAUGHT: " ); 00926 } 00927 00928 00929 /** 00930 * Helper for YUI_RETHROW() 00931 **/ 00932 template<class _Exception> 00933 void _YUI_RETHROW( const _Exception & exception_r, const YCodeLocation & where_r ) 00934 { 00935 YUIException::log( exception_r, where_r, "RETHROW: " ); 00936 exception_r.relocate( where_r ); 00937 throw; 00938 } 00939 00940 00941 #endif // YUIException_h