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), "") 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; }
327 { _where = newLocation; }
334 const std::string &
msg()
const 351 static std::string strErrno(
int errno_r );
356 static std::string strErrno(
int errno_r,
const std::string & msg );
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;
392 std::ostream & dumpError( std::ostream & str )
const;
459 :
YUIException( std::string(
"No widget with ID " ) + idString )
541 virtual std::ostream & dumpOn( std::ostream & str )
const = 0;
570 virtual std::ostream & dumpOn( std::ostream & str )
const;
595 YPropertyType
type()
const {
return _type; }
603 virtual std::ostream & dumpOn( std::ostream & str )
const;
631 virtual std::ostream & dumpOn( std::ostream & str )
const;
641 const std::string & message =
"" )
643 { setMsg( message ); }
654 virtual std::ostream & dumpOn( std::ostream & str )
const;
669 , _container( container )
686 virtual std::ostream &
dumpOn( std::ostream & str )
const 688 std::string widgetClass =
692 return str <<
"Too many children for " 719 , _container( container )
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
780 :
YUIException( std::string(
"Unsupported optional widget type: " ) + widgetType )
796 :
YUIException(
"Invalid dimension (neither YD_HORIZ nor YD_VERT)" )
821 const std::string & msg =
"" )
823 , _invalidIndex( invalidIndex )
824 , _validMin( validMin )
825 , _validMax( 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
879 :
YUIException( std::string(
"Couldn't load plug-in " ) + pluginName )
926 template<
class _Exception>
927 void _YUI_THROW(
const _Exception & exception_r,
const YCodeLocation & where_r )
929 exception_r.relocate( where_r );
931 throw( exception_r );
938 template<
class _Exception>
939 void _YUI_CAUGHT(
const _Exception & exception_r,
const YCodeLocation & where_r )
948 template<
class _Exception>
949 void _YUI_RETHROW(
const _Exception & exception_r,
const YCodeLocation & where_r )
952 exception_r.relocate( where_r );
957 #endif // YUIException_h YProperty property() const
Returns the property that caused this exception.
YPropertyType type() const
Return the property type the application tried to set.
Exception class for "index out of range".
void relocate(const YCodeLocation &newLocation) const
Exchange location on rethrow.
Exception class for attempt to set a read-only property.
void setMsg(const std::string &msg)
Set a new message string.
Exception class for "too many children": Attempt to add a child to a widget class that can't handle c...
YWidget * child() const
Returns the child widget.
YWidget * container() const
Returns the container widget that can't handle that many children.
int line() const
Returns the source line number where the exception occured.
int validMax() const
Return the valid maximum index.
void setWidget(YWidget *w)
Set the corresponding widget.
YCodeLocation(const std::string &file_r, const std::string &func_r, int line_r)
Constructor.
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
friend std::ostream & operator<<(std::ostream &str, const YCodeLocation &obj)
Stream output.
Exception class for "value other than YD_HORIZ or YD_VERT used for dimension".
YWidget * container() const
Returns the container widget whose child should be removed etc.
std::string func() const
Returns the name of the function where the exception occured.
virtual const char * what() const
Return message string.
std::string file() const
Returns the source file name where the exception occured.
YUIIndexOutOfRangeException(int invalidIndex, int validMin, int validMax, const std::string &msg="")
Constructor.
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
Exception class for plugin load failure.
int validMin() const
Return the valid minimum index.
Exception class for "out of memory".
Exception class for "unknown property name": The application tried to set (or query) a property that ...
YCodeLocation()
Default constructor.
Class for widget properties.
Helper class for UI exceptions: Store FILE, FUNCTION and LINE.
const std::string & msg() const
Return the message string provided to the constructor.
Exception class for "property type mismatch": The application tried to set a property with a wrong ty...
static void log(const YUIException &exception, const YCodeLocation &location, const char *const prefix)
Drop a log line on throw, catch or rethrow.
Exception class for generic null pointer exceptions.
Exception class for "invalid child".
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
Exception class for UI plugin load failure.
std::string asString() const
Returns the location in normalized string format.
Abstract base class for widget property exceptions.
int invalidIndex() const
Return the offending index value.
const YCodeLocation & where() const
Return YCodeLocation.
Base class for UI Exceptions.
YWidget * widget() const
Returns the corresponding widget or 0 if there was none.