FW: [fdo-dev] Standard exceptions handling practice

Greg Boone greg.boone at autodesk.com
Fri Sep 1 12:15:53 EDT 2006


Robert makes a good point below. We have a mechanism built into the
FdoException class that allows the nesting of exception messages into a
pyramid format, allowing for successive routines to capture and add
contextual error information to a single FdoException which is then
caught by the calling application.

Here are the related methods on FdoException....

class FdoException : public FdoIDisposable
{
public:
    /// \brief
    ///  Returns an instance of a FdoException using the specified
arguments.
    /// 
    /// \param message 
    /// Input the error message
    /// \param cause 
    /// Input the cause of the error
    /// 
    /// \return
    /// Returns the FdoException object
    /// 
    FDO_API_COMMON static FdoException* Create(FdoString* message,
	
FdoException* cause);

    /// \brief
    /// Gets the message associated with this exception. If no message
is
    /// associated with this exception but it has a cause, then this
method
    /// returns the message specified for the cause exception. If no
message 
    /// and  no cause are associated with this exception then a null 
    /// reference is returned.
    /// 
    /// \return
    /// Returns the error message
    /// 
    FDO_API_COMMON virtual FdoString* GetExceptionMessage();

    /// \brief
    /// Gets a reference to the exception that caused this exception.
    /// 
    /// \return
    /// Returns the cause of the error
    /// 
    FDO_API_COMMON virtual FdoException* GetCause();

    /// \brief
    /// Gets a reference to the exception that is the root cause of this
    /// exception.
    /// 
    /// \return
    /// Returns the root cause for the error
    /// 
    FDO_API_COMMON virtual FdoException* GetRootCause();

    /// \brief
    /// Sets the cause exception
    /// 
    /// \param cause 
    /// Input the cause of the error
    /// 
    /// \return
    /// Returns nothing
    /// 
    FDO_API_COMMON virtual void SetCause( FdoException* cause );


Here is a simple example of catching an exception and adding a new error
message to the FdoException pyramid....

e.g.  

try 
{
	Foo();
} 
catch (FdoException* cause) 
{
    // Failed foo(). Create a new nested exception
    // taking the caught exception as the cause
    throw FdoException::Create(
	NlsMsgGet(ABC_76_FAIL_FOO, "Failed executing Foo()."), cause);
}

Greg

-----Original Message-----
From: Robert Fortin 
Sent: Friday, September 01, 2006 11:04 AM
To: Greg Boone
Subject: RE: [fdo-dev] Standard exceptions handling practice

You could mention that the FdoException.Cause will include the nested
exception in case the exception is capture an translated into more
appropriate message.  I don't think this is done systematically by every
provider but that what should be implemented so the underneath exception
from the 3rd party is not obscured by the provider. 

-----Original Message-----
From: Greg Boone 
Sent: Friday, September 01, 2006 10:56 AM
To: dev at fdo.osgeo.org
Subject: RE: [fdo-dev] Standard exceptions handling practice

When dealing with 3rd party exceptions, we try our *best* to catch these
exceptions in the provider code base and translate the contents of the
exception into an FdoException. We then throw the FdoException. Our main
clients such as Map and MapGuide are set up to catch instances of
FdoException when executing FDO logic and allowing other exceptions to
be thrown when executing provider code could severely compromise their
error handling strategies.

Greg 

-----Original Message-----
From: Mateusz Loskot [mailto:mateusz at loskot.net]
Sent: Thursday, August 31, 2006 11:40 PM
To: dev at fdo.osgeo.org
Subject: [fdo-dev] Standard exceptions handling practice

Hi,

As I see, FDO uses non-standard exceptions.
What is the recommended practice in FDO [1] to handle standard
exceptions?
For example, when using some operations from C++ Standard Library or
Boost that may throw exception (standard exception), how should I handle
them in FDO code?
Am I supposed to convert every standard exception to one of the FDO
exception and re-thrown?

[1] I use FDO to name all FDO projects and their sources, not only
fdocore.

Cheers
--
Mateusz Loskot
http://mateusz.loskot.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe at fdo.osgeo.org For additional
commands, e-mail: dev-help at fdo.osgeo.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe at fdo.osgeo.org For additional
commands, e-mail: dev-help at fdo.osgeo.org






More information about the Fdo-internals mailing list