2002 2003 2004 2005 <2006> 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 | Index | 2002 2003 2004 2005 <2006> 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 |
<== Date ==> | <== Thread ==> |
---|
Subject: | 3.15 C++ Exception classes |
From: | Andrew Johnson <[email protected]> |
To: | EPICS core-talk <[email protected]> |
Date: | Mon, 20 Feb 2006 17:21:08 -0600 |
struct Diagnostic : exception { public:enum severity_t { sevWarning, sevError, sevFatal };virtual severity_t severity () const = 0; virtual void context ( StringSegment & ) const = 0; };
Having recently committed my StringReader and StringEditor interfaces and some implementations to the 3.15 CVS tree for Jeff to use in DataAccess, I am looking at designing a modified version of this class for general use. The main point of this email is to document what I'm currently implementing, but I guess that this may result in some discussion from Jeff and others as well.
severity(): I don't like this; the severity information should be implicit in the hierarchy of the class that is being thrown. I expect to be able to write a try/catch phrase that could catch warnings but not errors or fatalities; I don't want to catch everything and then have to re-throw anything that's more severe than a warning. I'm also not convinced that the thrower can determine the severity of an exception in practice. Therefore I'm not going to include the severity part.
context(): I'm replacing Jeff's StringSegment with a StringEditor and renaming this function to what(), since it performs the exact same role as the std::exception::what() function, namely provides a way to convert the exception data into a displayable string.
status(): We often provide wrappers to allow C code to call C++ code. The C routines can't trap exceptions, so those C++ wrappers may have to convert such exceptions into a long integer status value. The exception object is the obvious thing to know what status value to return, so I'm considering adding this method to provide that. If the conversion to the single C status value would lose diagnostic data that is stored in the exception object, this routine can log that information to the error logger at that time - status() should only be called once, when the exception is about to be passed to C code.
Here's my current replacement base class: class BaseException : public std::exception { public: virtual void what(StringEditor &str) const = 0; virtual long status() const { return S_exc_exception; } }; - Andrew -- There is no S in exprexxo.