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() ); \
176 #define YUI_CHECK_WIDGET( WIDGET ) \
179 if ( ! (WIDGET) || ! (WIDGET)->isValid() ) \
181 YUI_THROW( YUIInvalidWidgetException() ); \
192 #define YUI_CHECK_INDEX_MSG( INDEX, VALID_MIN, VALID_MAX, MSG ) \
195 if ( (INDEX) < (VALID_MIN) || \
196 (INDEX) > (VALID_MAX) ) \
198 YUI_THROW( YUIIndexOutOfRangeException( (INDEX), (VALID_MIN), (VALID_MAX), (MSG) ) ); \
203 #define YUI_CHECK_INDEX( INDEX, VALID_MIN, VALID_MAX ) \
204 YUI_CHECK_INDEX_MSG( (INDEX), (VALID_MIN), (VALID_MAX), "")
221 const std::string & func_r,
238 std::string
file()
const {
return _file; }
243 std::string
func()
const {
return _func; }
248 int line()
const {
return _line; }
271 std::ostream & operator<<( std::ostream & str,
const YCodeLocation & obj );
311 { _where = newLocation; }
318 const std::string &
msg()
const
335 static std::string
strErrno(
int errno_r );
340 static std::string
strErrno(
int errno_r,
const std::string &
msg );
348 const char *
const prefix );
354 virtual const char *
what()
const throw()
355 {
return _msg.c_str(); }
362 virtual std::ostream &
dumpOn( std::ostream & str )
const;
376 std::ostream & dumpError( std::ostream & str )
const;
384 std::ostream & operator<<( std::ostream & str,
const YUIException & obj );
443 :
YUIException( std::string(
"No widget with ID " ) + idString )
525 virtual std::ostream &
dumpOn( std::ostream & str )
const = 0;
554 virtual std::ostream &
dumpOn( std::ostream & str )
const;
579 YPropertyType
type()
const {
return _type; }
587 virtual std::ostream &
dumpOn( std::ostream & str )
const;
615 virtual std::ostream &
dumpOn( std::ostream & str )
const;
625 const std::string & message =
"" )
638 virtual std::ostream &
dumpOn( std::ostream & str )
const;
653 , _container( container )
670 virtual std::ostream &
dumpOn( std::ostream & str )
const
672 std::string widgetClass =
676 return str <<
"Too many children for "
703 , _container( container )
726 virtual std::ostream &
dumpOn( std::ostream & str )
const
728 std::string containerWidgetClass =
732 std::string childWidgetClass =
736 return str << childWidgetClass
737 <<
" is not a child of "
738 << containerWidgetClass
764 :
YUIException( std::string(
"Unsupported optional widget type: " ) + widgetType )
780 :
YUIException(
"Invalid dimension (neither YD_HORIZ nor YD_VERT)" )
805 const std::string &
msg =
"" )
807 , _invalidIndex( invalidIndex )
808 , _validMin( validMin )
809 , _validMax( validMax )
836 virtual std::ostream &
dumpOn( std::ostream & str )
const
838 std::string prefix =
msg();
840 if ( prefix.empty() )
841 prefix =
"Index out of range";
843 return str << prefix <<
": " << _invalidIndex
844 <<
" valid: " << _validMin <<
" .. " << _validMax
863 :
YUIException( std::string(
"Couldn't load plug-in " ) + pluginName )
910 template<
class _Exception>
911 void _YUI_THROW(
const _Exception & exception_r,
const YCodeLocation & where_r )
913 exception_r.relocate( where_r );
915 throw( exception_r );
922 template<
class _Exception>
923 void _YUI_CAUGHT(
const _Exception & exception_r,
const YCodeLocation & where_r )
932 template<
class _Exception>
933 void _YUI_RETHROW(
const _Exception & exception_r,
const YCodeLocation & where_r )
936 exception_r.relocate( where_r );
941 #endif // YUIException_h