Hi
> > You can use SetLastError and GetLastError, but I don't
> > suggest them. I suggest you just feed an error code into the
> > exception, like:
Good idea, but you're better off using different exception types to
enums (that's how excpetions are meant to work) and/or passing the
message back.
class Exception
{
public:
Exception( const std::string& msg )
: msg_( msg )
{
}
std::string What() const
{
return msg_;
}
private:
std::string msg_;
};
void parser_internal()
{
if (something_bad())
{
throw Exception( "Something went badly wrong!" );
}
}
> void parser_external()
> > {
> > try
> > {
> > parser_internal();
> > }
> > catch (Exception & ex)
(This should be const Exception& e so that a copy isn't made.
> > {
std::cout << ex.What() << std::endl;
> > }
> > }
>
> Would this exception class be derived from CException?
I certianly doesn't need to be. You can throw and catch any object you
like. I even caught a contractor throwing and ctaching string literals
one (very bad!!). I would, however, recomend deriving form
std::excrption and chaning the above interface accordingly.
> Would I have to "delete" the exception when caught?
Nope. It's no allocated on the heap, is it?
Regards
Paul
Paul Grenyer
Email: [EMAIL PROTECTED]
Web: http://www.paulgrenyer.co.uk
Have you met Aeryn: http://www.paulgrenyer.co.uk/aeryn/?
Version 0.3.0 beta now available for download.
_______________________________________________
msvc mailing list
[EMAIL PROTECTED]
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for subscription
changes, and list archive.