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
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
virtual ~YUIException()
Destructor.
std::string asString() const
Returns the location in normalized string format.
virtual std::ostream & dumpOn(std::ostream &str) const =0
Write proper error message with all relevant data.
const YCodeLocation & where() const
Return YCodeLocation.
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
Exception class for "index out of range".
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...
int line() const
Returns the source line number where the exception occured.
const std::string & msg() const
Return the message string provided to the constructor.
virtual const char * what() const
Return message string.
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
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.
YWidget * container() const
Returns the container widget that can't handle that many children.
Exception class for "value other than YD_HORIZ or YD_VERT used for dimension".
YWidget * widget() const
Returns the corresponding widget or 0 if there was none.
friend std::ostream & operator<<(std::ostream &str, const YUIException &obj)
YUIException stream output.
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
YUIIndexOutOfRangeException(int invalidIndex, int validMin, int validMax, const std::string &msg="")
Constructor.
Exception class for plugin load failure.
std::string asString() const
Error message provided by dumpOn as string.
Exception class for "out of memory".
Exception class for "unknown property name": The application tried to set (or query) a property tha...
YProperty property() const
Returns the property that caused this exception.
YCodeLocation()
Default constructor.
YUIException()
Default constructor.
std::string func() const
Returns the name of the function where the exception occured.
Class for widget properties.
int validMax() const
Return the valid maximum index.
int validMin() const
Return the valid minimum index.
Helper class for UI exceptions: Store FILE, FUNCTION and LINE.
void relocate(const YCodeLocation &newLocation) const
Exchange location on rethrow.
Exception class for "property type mismatch": The application tried to set a property with a wrong ty...
YPropertyType type() const
Return the property type the application tried to set.
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.
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
int invalidIndex() const
Return the offending index value.
YWidget * child() const
Returns the child widget.
Exception class for "invalid child".
static std::string strErrno(int errno_r)
Make a string from errno_r.
Exception class for UI plugin load failure.
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
Abstract base class for widget property exceptions.
Base class for UI Exceptions.
YWidget * container() const
Returns the container widget whose child should be removed etc.
std::string file() const
Returns the source file name where the exception occured.