|
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
> news:1093230456.8377.44.camel_at_base.torri.org...
> > Are there any guidelines on where and when to use exceptions?
>
> See http://www.boost.org/more/error_handling.html
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(),
m_msg(msg)
{}
// Specify virtual functions?
virtual const char* what() const throw()
{
try
{
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;
}
}
private:
std::string m_msg;
};
Stephen
-- Email: storri_at_[hidden]
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net