Boost logo

Boost Users :

From: Stephen torri (storri_at_[hidden])
Date: 2004-08-22 23:40:57

On Sun, 2004-08-22 at 23:41, Jonathan Turkanis wrote:
> "Stephen torri" <storri_at_[hidden]> wrote in message
> > Are there any guidelines on where and when to use exceptions?
> See

Thanks for the link. I had already found this link but was confused on
some of advice it gave. The question below are some of my confusion
about using exceptions wisely. What I am seeking for each of them is an
example explaining how it implements a solution.

1) Use virutal inheritance. I see the example and can understand why
its wrong I just do not understand how to fix it.
2) Don't embed a std::string ... How can I use the data I have at the
point of the error safely? I want to provide a debug message to the user
that will lead them to the answer. This affects 6) Expose relevant
information about the cause of the error.

In my project I have a base class called BaseException that inherits
from std::exception.

class BaseException : public std::exception
        // virtual functions?
        virtual const char* what() const throw() = 0;

I want exceptions in the code to be obvious to what is wrong but use the
what() message to say why:

class DataTypeException : public BaseException
        DataTypeException (std::string msg)
        : Base_Exception(),

        // Specify virtual functions?
        virtual const char* what() const throw()
                std::stringstream output;
                output << m_exception_name << ": " << m_message.c_str()
                               << std::endl;
                 return (output.str()).c_str();
         catch(std::exception &)
                return m_exception_name;

        std::string m_msg;


Email: storri_at_[hidden]

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at