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; }
287 std::ostream & operator<<( std::ostream & str,
const YCodeLocation & obj );
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;
400 std::ostream & operator<<( std::ostream & str,
const YUIException & obj );
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 =
"" )
654 virtual std::ostream &
dumpOn( std::ostream & str )
const;
686 virtual std::ostream &
dumpOn( std::ostream & str )
const
688 std::string widgetClass =
692 return str <<
"Too many children for "
742 virtual std::ostream &
dumpOn( std::ostream & str )
const
744 std::string containerWidgetClass =
748 std::string childWidgetClass =
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 =
"" )
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 );
Helper class for UI exceptions: Store FILE, FUNCTION and LINE.
std::string asString() const
Returns the location in normalized string format.
std::string func() const
Returns the name of the function where the exception occured.
std::string file() const
Returns the source file name where the exception occured.
int line() const
Returns the source line number where the exception occured.
friend std::ostream & operator<<(std::ostream &str, const YCodeLocation &obj)
Stream output.
YCodeLocation(const std::string &file_r, const std::string &func_r, int line_r)
Constructor.
YCodeLocation()
Default constructor.
Class for widget properties.
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
Exception class for UI plugin load failure.
Base class for UI Exceptions.
friend std::ostream & operator<<(std::ostream &str, const YUIException &obj)
YUIException stream output.
static std::string strErrno(int errno_r)
Make a string from errno_r.
void relocate(const YCodeLocation &newLocation) const
Exchange location on rethrow.
virtual ~YUIException()
Destructor.
std::string asString() const
Error message provided by dumpOn as string.
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
virtual const char * what() const
Return message string.
void setMsg(const std::string &msg)
Set a new message string.
YUIException()
Default constructor.
static void log(const YUIException &exception, const YCodeLocation &location, const char *const prefix)
Drop a log line on throw, catch or rethrow.
const YCodeLocation & where() const
Return YCodeLocation.
const std::string & msg() const
Return the message string provided to the constructor.
Exception class for "index out of range".
int validMin() const
Return the valid minimum index.
int validMax() const
Return the valid maximum index.
int invalidIndex() const
Return the offending index value.
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 "invalid child".
YWidget * child() const
Returns the child widget.
YWidget * container() const
Returns the container widget whose child should be removed etc.
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
Exception class for "value other than YD_HORIZ or YD_VERT used for dimension".
Exception class for generic null pointer exceptions.
Exception class for "out of memory".
Exception class for plugin load failure.
Abstract base class for widget property exceptions.
virtual std::ostream & dumpOn(std::ostream &str) const =0
Write proper error message with all relevant data.
YProperty property() const
Returns the property that caused this exception.
void setWidget(YWidget *w)
Set the corresponding widget.
YWidget * widget() const
Returns the corresponding widget or 0 if there was none.
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.
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
Exception class for attempt to set a read-only property.
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
Exception class for "too many children": Attempt to add a child to a widget class that can't handle c...
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.
YWidget * container() const
Returns the container widget that can't handle that many children.
Exception class for "unknown property name": The application tried to set (or query) a property that ...
virtual std::ostream & dumpOn(std::ostream &str) const
Write proper error message with all relevant data.