28 #ifndef YUIException_h
29 #define YUIException_h
36 #include "YProperty.h"
84 #define YUI_EXCEPTION_CODE_LOCATION YCodeLocation(__FILE__,__FUNCTION__,__LINE__)
90 #define YUI_THROW( EXCEPTION ) \
91 _YUI_THROW( ( EXCEPTION ), YUI_EXCEPTION_CODE_LOCATION )
96 #define YUI_CAUGHT( EXCEPTION ) \
97 _YUI_CAUGHT( ( EXCEPTION ), YUI_EXCEPTION_CODE_LOCATION )
103 #define YUI_RETHROW( EXCEPTION ) \
104 _YUI_RETHROW( ( EXCEPTION ), YUI_EXCEPTION_CODE_LOCATION )
110 #define YUI_THROW_MSG( EXCEPTION_TYPE, MSG ) \
111 YUI_THROW( EXCEPTION_TYPE( MSG ) )
117 #define YUI_THROW_ERRNO( EXCEPTION_TYPE ) \
118 YUI_THROW( EXCEPTION_TYPE( YUIException::strErrno( errno ) ) )
123 #define YUI_THROW_ERRNO1( EXCEPTION_TYPE, ERRNO ) \
124 YUI_THROW( EXCEPTION_TYPE( YUIException::strErrno( ERRNO ) ) )
129 #define YUI_THROW_ERRNO_MSG( EXCEPTION_TYPE, MSG) \
130 YUI_THROW( EXCEPTION_TYPE( YUIException::strErrno( errno, MSG ) ) )
135 #define YUI_THROW_ERRNO_MSG1( EXCEPTION_TYPE, ERRNO,MSG ) \
136 YUI_THROW( EXCEPTION_TYPE( YUIException::strErrno( ERRNO, MSG ) ) )
147 #define YUI_CHECK_NEW( PTR ) \
152 YUI_THROW( YUIOutOfMemoryException() ); \
162 #define YUI_CHECK_PTR( PTR ) \
167 YUI_THROW( YUINullPointerException() ); \
191 #define YUI_CHECK_WIDGET( WIDGET ) \
194 if ( ! ( static_cast<bool> (WIDGET) ) || \
195 ! (WIDGET)->isValid() ) \
197 YUI_THROW( YUIInvalidWidgetException() ); \
208 #define YUI_CHECK_INDEX_MSG( INDEX, VALID_MIN, VALID_MAX, MSG ) \
211 if ( (INDEX) < (VALID_MIN) || \
212 (INDEX) > (VALID_MAX) ) \
214 YUI_THROW( YUIIndexOutOfRangeException( (INDEX), (VALID_MIN), (VALID_MAX), (MSG) ) ); \
219 #define YUI_CHECK_INDEX( INDEX, VALID_MIN, VALID_MAX ) \
220 YUI_CHECK_INDEX_MSG( (INDEX), (VALID_MIN), (VALID_MAX), "")
236 YCodeLocation(
const std::string & file_r,
237 const std::string & func_r,
254 std::string file()
const {
return _file; }
259 std::string func()
const {
return _func; }
264 int line()
const {
return _line; }
269 std::string asString()
const;
274 friend std::ostream & operator<<( std::ostream & str,
const YCodeLocation & obj );
287 std::ostream & operator<<( std::ostream & str,
const YCodeLocation & obj );
297 class YUIException :
public std::exception
310 YUIException(
const std::string & msg_r );
315 virtual ~YUIException() throw();
320 const YCodeLocation & where()
const
326 void relocate(
const YCodeLocation & newLocation )
const
327 { _where = newLocation; }
334 const std::string & msg()
const
340 void setMsg(
const std::string & msg )
346 std::string asString()
const;
351 static std::string strErrno(
int errno_r );
356 static std::string strErrno(
int errno_r,
const std::string & msg );
362 static void log(
const YUIException & exception,
363 const YCodeLocation & location,
364 const char *
const prefix );
370 virtual const char * what()
const throw()
371 {
return _msg.c_str(); }
378 virtual std::ostream & dumpOn( std::ostream & str )
const;
382 friend std::ostream & operator<<( std::ostream & str,
const YUIException & obj );
385 mutable YCodeLocation _where;
392 std::ostream & dumpError( std::ostream & str )
const;
400 std::ostream & operator<<( std::ostream & str,
const YUIException & obj );
407 class YUINullPointerException:
public YUIException
410 YUINullPointerException()
411 : YUIException(
"Null pointer" )
414 virtual ~YUINullPointerException() throw()
423 class YUIOutOfMemoryException:
public YUIException
426 YUIOutOfMemoryException()
427 : YUIException(
"Out of memory" )
430 virtual ~YUIOutOfMemoryException() throw()
440 class YUIInvalidWidgetException:
public YUIException
443 YUIInvalidWidgetException()
444 : YUIException(
"Invalid widget" )
447 virtual ~YUIInvalidWidgetException() throw()
455 class YUIWidgetNotFoundException:
public YUIException
458 YUIWidgetNotFoundException(
const std::string & idString )
459 : YUIException( std::string(
"No widget with ID " ) + idString )
462 virtual ~YUIWidgetNotFoundException() throw()
467 class YUINoDialogException:
public YUIException
470 YUINoDialogException()
471 : YUIException(
"No dialog existing" )
474 virtual ~YUINoDialogException() throw()
479 class YUIDialogStackingOrderException:
public YUIException
482 YUIDialogStackingOrderException()
483 : YUIException(
"Dialog stacking order violated" )
486 virtual ~YUIDialogStackingOrderException() throw()
491 class YUISyntaxErrorException:
public YUIException
494 YUISyntaxErrorException(
const std::string & msg )
495 : YUIException( msg )
498 virtual ~YUISyntaxErrorException() throw()
506 class YUIPropertyException:
public YUIException
509 YUIPropertyException(
const YProperty & prop,
516 virtual ~YUIPropertyException() throw()
523 YProperty property()
const {
return _property; }
528 YWidget * widget()
const {
return _widget; }
533 void setWidget(
YWidget * w ) { _widget = w; }
541 virtual std::ostream & dumpOn( std::ostream & str )
const = 0;
553 class YUIUnknownPropertyException:
public YUIPropertyException
556 YUIUnknownPropertyException(
const std::string & propertyName,
558 : YUIPropertyException(
YProperty( propertyName, YUnknownPropertyType ), widget )
561 virtual ~YUIUnknownPropertyException() throw()
570 virtual std::ostream & dumpOn( std::ostream & str )
const;
578 class YUIPropertyTypeMismatchException:
public YUIPropertyException
582 YUIPropertyTypeMismatchException(
const YProperty & property,
585 : YUIPropertyException( property, widget )
589 virtual ~YUIPropertyTypeMismatchException() throw()
595 YPropertyType type()
const {
return _type; }
603 virtual std::ostream & dumpOn( std::ostream & str )
const;
613 class YUISetReadOnlyPropertyException:
public YUIPropertyException
617 YUISetReadOnlyPropertyException(
const YProperty & property,
619 : YUIPropertyException( property, widget )
622 virtual ~YUISetReadOnlyPropertyException() throw()
631 virtual std::ostream & dumpOn( std::ostream & str )
const;
635 class YUIBadPropertyArgException:
public YUIPropertyException
639 YUIBadPropertyArgException(
const YProperty & property,
641 const std::string & message =
"" )
642 : YUIPropertyException( property, widget )
643 { setMsg( message ); }
645 virtual ~YUIBadPropertyArgException() throw()
654 virtual std::ostream & dumpOn( std::ostream & str )
const;
663 template<
class YW
idget>
class YUITooManyChildrenException:
public YUIException
667 YUITooManyChildrenException(
YWidget * container )
668 : YUIException(
"Too many children" )
669 , _container( container )
672 virtual ~YUITooManyChildrenException() throw()
678 YWidget * container()
const {
return _container; }
686 virtual std::ostream & dumpOn( std::ostream & str )
const
688 std::string widgetClass =
692 return str <<
"Too many children for "
712 template<
class YW
idget>
class YUIInvalidChildException:
public YUIException
716 YUIInvalidChildException(
YWidget * container,
718 : YUIException(
"Invalid child" )
719 , _container( container )
723 virtual ~YUIInvalidChildException() throw()
729 YWidget * container()
const {
return _container; }
734 YWidget * child()
const {
return _child; }
742 virtual std::ostream & dumpOn( std::ostream & str )
const
744 std::string containerWidgetClass =
748 std::string childWidgetClass =
749 child() ? child()->widgetClass() :
752 return str << childWidgetClass
753 <<
" is not a child of "
754 << containerWidgetClass
775 class YUIUnsupportedWidgetException:
public YUIException
779 YUIUnsupportedWidgetException(
const std::string & widgetType )
780 : YUIException( std::string(
"Unsupported optional widget type: " ) + widgetType )
783 virtual ~YUIUnsupportedWidgetException() throw()
792 class YUIInvalidDimensionException:
public YUIException
795 YUIInvalidDimensionException()
796 : YUIException(
"Invalid dimension (neither YD_HORIZ nor YD_VERT)" )
799 virtual ~YUIInvalidDimensionException() throw()
807 class YUIIndexOutOfRangeException:
public YUIException
818 YUIIndexOutOfRangeException(
int invalidIndex,
821 const std::string & msg =
"" )
822 : YUIException( msg )
823 , _invalidIndex( invalidIndex )
824 , _validMin( validMin )
825 , _validMax( validMax )
828 virtual ~YUIIndexOutOfRangeException() throw()
834 int invalidIndex()
const {
return _invalidIndex; }
839 int validMin()
const {
return _validMin; }
844 int validMax()
const {
return _validMax; }
852 virtual std::ostream & dumpOn( std::ostream & str )
const
854 std::string prefix = msg();
856 if ( prefix.empty() )
857 prefix =
"Index out of range";
859 return str << prefix <<
": " << _invalidIndex
860 <<
" valid: " << _validMin <<
" .. " << _validMax
875 class YUIPluginException:
public YUIException
878 YUIPluginException(
const std::string & pluginName )
879 : YUIException( std::string(
"Couldn't load plug-in " ) + pluginName )
882 virtual ~YUIPluginException() throw()
890 class YUICantLoadAnyUIException:
public YUIException
893 YUICantLoadAnyUIException()
894 : YUIException(
"No $DISPLAY and stdout is not a tty" )
897 virtual ~YUICantLoadAnyUIException() throw()
905 class YUIButtonRoleMismatchException:
public YUIException
909 YUIButtonRoleMismatchException(
const std::string & msg )
910 : YUIException( msg )
913 virtual ~YUIButtonRoleMismatchException() throw()
926 template<
class _Exception>
927 void _YUI_THROW(
const _Exception & exception_r,
const YCodeLocation & where_r )
929 exception_r.relocate( where_r );
930 YUIException::log( exception_r, where_r,
"THROW: " );
931 throw( exception_r );
938 template<
class _Exception>
939 void _YUI_CAUGHT(
const _Exception & exception_r,
const YCodeLocation & where_r )
941 YUIException::log( exception_r, where_r,
"CAUGHT: " );
948 template<
class _Exception>
949 void _YUI_RETHROW(
const _Exception & exception_r,
const YCodeLocation & where_r )
951 YUIException::log( exception_r, where_r,
"RETHROW: " );
952 exception_r.relocate( where_r );
957 #endif // YUIException_h
Class for widget properties.