Sunday, July 7, 2013

Exception handling problem

Newsgroup: comp.lang.c++

Subject: Exception handling problem

From: woodbrian77@...

Date: Wed, 3 Jul 2013 13:33:13 -0700 (PDT)



I'm not sure if the following is due to a misunderstanding

on my part or a clang 3.2 problem. Notice the two catch

blocks below.



try{

// ...

}catch(eof const& ex){

syslog(LOG_ERR,"Got end of stream notice: %s",ex.what());

// ...

}catch(::std::exception const& ex){

syslog(LOG_ERR,"Problem handling response %s",ex.what());

// ...

}



In a test I've caused my back tier to close it's connection

to the middle tier every 500th request. The code above is

from the middle tier. I have two definitions of the eof

class:



#if 0

class eof : public failure {



public:

explicit eof (char const* what_) : failure(what_)

{}



~eof () throw()

{}

};



#else



class eof : public ::std::exception {

::std::string whatStr;



public:

explicit eof (char const* what_) : whatStr(what_)

{}



~eof () throw()

{}



char const* what () const throw()

{ return whatStr.c_str(); }



template <class T>

eof& operator<< (T val)

{

::std::ostringstream ss;

ss << val;

whatStr.append(ss.str().c_str());

return *this;

}

};



#endif



If I use the second, longer form, an eof exception is

caught as expected. But if I build the middle tier with

the shorter form of eof, the handler for std::exception

is the one used. This code and the definition of failure

is here --

http://webEbenezer.net/misc/ErrorWords.hh



I'd prefer to use the shorter form, but can't at this point.

Thanks in advance.





Brian

Ebenezer Enterprises - In G-d we trust.

http://webEbenezer.net







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?34941-Exception-handling-problem&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

No comments:

Post a Comment