C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

unexpected shame^w exception
Goto page 1, 2  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
news@pgxml.net
Guest





PostPosted: Thu Oct 14, 2004 10:00 pm    Post subject: unexpected shame^w exception Reply with quote



Hi!

As the subject hints i recently had to deal with an unexpected
exception.

Context in short (one of the calling methods promised to throw only
runtime_error):

enum Blah { ja,nein,mir_egal } blah;

inline SomeStream& operator >> ( SomeStream& stream,
Blah& myBlah ) {
unsigned int tmp;
stream >> tmp;
myBlah = static_cast< Blah >( tmp );
return stream;
}

Do not ask, i know myself its not a good idea to code java and c++ in
parallel. ;-)

So my "masterpiece" terminated with a SIGABRT (linux-box), leaving me
with ??? in my eyes staring a the core dump.

In this case a "-fno-enforce-eh-specs" in the g++ flags helped me to
find out that there was a bad_cast in play, but that cant be it.

if i set a handler via set_unexpected( some_handler ), the handler
only gets the information that there *was* a unexpected exception, but
not from where and which one, right?

I fear its getting compiler-specific, but are there any more or less
"standard-compliant" ways to get more information about the
evil-doer[1]? Dirty fantasies or just URIs are welcome.

cu!

christoph

Footnotes:
[1] except the PEBKAC?

--
sig? *sigh*

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Alberto Barbati
Guest





PostPosted: Fri Oct 15, 2004 11:30 am    Post subject: Re: unexpected shame^w exception Reply with quote



[email]news (AT) pgxml (DOT) net[/email] wrote:
Quote:
Hi!

As the subject hints i recently had to deal with an unexpected
exception.

Context in short (one of the calling methods promised to throw only
runtime_error):

enum Blah { ja,nein,mir_egal } blah;

inline SomeStream& operator >> ( SomeStream& stream,
Blah& myBlah ) {
unsigned int tmp;
stream >> tmp;
myBlah = static_cast< Blah >( tmp );
return stream;
}

I think you got the context a bit too short... What's SomeStream? I
assume SomeStream is a standard istream.

Quote:
Do not ask, i know myself its not a good idea to code java and c++ in
parallel. Wink

I won't ask. Why should I?

Quote:
In this case a "-fno-enforce-eh-specs" in the g++ flags helped me to
find out that there was a bad_cast in play, but that cant be it.

A bad_cast? That's an interesting piece of info. It *can* be it, indeed.
One thing that might throw a bad_cast in the code above is the access to
the stream's locale facet num_get. Either:

1) you messed up with the stream's locale
2) SomeStream is (or is derived from) basic_istream<> with a char_type
which is not either char or wchar_t

Quote:
if i set a handler via set_unexpected( some_handler ), the handler
only gets the information that there *was* a unexpected exception, but
not from where and which one, right?

Right, set_unexpected won't help you very much.

Quote:
I fear its getting compiler-specific, but are there any more or less
"standard-compliant" ways to get more information about the
evil-doer[1]? Dirty fantasies or just URIs are welcome.

Usually executing the code in a debugger is the easiest way. Most (if
not all) modern debuggers allow you to break execution just before an
exception is thrown.

HTH,

Alberto

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Vitaly Repin
Guest





PostPosted: Fri Oct 15, 2004 9:56 pm    Post subject: Re: unexpected shame^w exception Reply with quote



Hello!

Yes, I can introduce one "standard-compliant" way to get
some information of the exception:

void log_exception_info() throw()
{
try {
throw;
} catch (std::exception& e) {
logg(Lvl_error, "Exception what() = %s", prefix, e.what());
logg(Lvl_error, "exception RTTI: %s", prefix, typeid(e).name());
} catch (...) {
logg(Lvl_error, "There is no information about that exception, sorry");
}
};

You simply re-generate the last exception. If unexpected exception
was derived from std::exception, it's virtual member function what()
is executed. Otherwise, only non-meaningful message is printed.
That's whay I prefer to derive my exceptions from one base class,
std::exception.

[email]news (AT) pgxml (DOT) net[/email] wrote in message news:<87655dvzsc.fsf (AT) gandalf (DOT) pgxml.net>...
Quote:
if i set a handler via set_unexpected( some_handler ), the handler
only gets the information that there *was* a unexpected exception, but
not from where and which one, right?

I fear its getting compiler-specific, but are there any more or less
"standard-compliant" ways to get more information about the
evil-doer[1]? Dirty fantasies or just URIs are welcome.

Good bye!
--
WBR & WBW, Vitaly

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Michael Karcher
Guest





PostPosted: Fri Oct 15, 2004 10:50 pm    Post subject: Re: unexpected shame^w exception Reply with quote

Alberto Barbati <AlbertoBarbati (AT) libero (DOT) it> wrote:
Quote:
Usually executing the code in a debugger is the easiest way. Most (if
not all) modern debuggers allow you to break execution just before an
exception is thrown.

JFTR, as gcc was mentioned: gdb 6.1 on i386 (at least on my debian box) says
"sorry, not implemented" on "catch throw", but it works to set a breakpoint
on __cxa_throw.

Michael Karcher

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
John Torjo
Guest





PostPosted: Fri Oct 15, 2004 11:21 pm    Post subject: Re: unexpected shame^w exception Reply with quote

[email]news (AT) pgxml (DOT) net[/email] wrote in message news:<87655dvzsc.fsf (AT) gandalf (DOT) pgxml.net>...
Quote:
Hi!

As the subject hints i recently had to deal with an unexpected
exception.

Context in short (one of the calling methods promised to throw only
runtime_error):
[...]

I really don't think you've provided us with enough information to do
any judgement. Could you be a little more specific?

Best,
John

John Torjo, Contributing editor, C/C++ Users Journal
-- "Win32 GUI Generics" -- generics & GUI do mix, after all
-- http://www.torjo.com/win32gui/
-- v1.5 - tooltips at your fingertips (work for menus too!)
+ bitmap buttons, tab dialogs, hyper links, lite html

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
news@pgxml.net
Guest





PostPosted: Sun Oct 17, 2004 1:40 am    Post subject: Re: unexpected shame^w exception Reply with quote

[email]jtorjo (AT) yahoo (DOT) com[/email] (John Torjo) writes:

Quote:
news (AT) pgxml (DOT) net wrote in message
news:<87655dvzsc.fsf (AT) gandalf (DOT) pgxml.net>...
Hi!

As the subject hints i recently had to deal with an unexpected
exception.

Context in short (one of the calling methods promised to throw only
runtime_error): [...]

I really don't think you've provided us with enough information to do
any judgement. Could you be a little more specific?

Hm.. no. I think it should be less specific. The problem is not that
stream that threw that exception (code that i will throw away anyway), i
am looking for means to deal with unexpected exceptions. Just terminate
a program without any information why cant be it. What if you linked
against a third party lib that throws something unkown?

cu!

christoph

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
news@pgxml.net
Guest





PostPosted: Sun Oct 17, 2004 1:41 am    Post subject: Re: unexpected shame^w exception Reply with quote

[email]programm (AT) metrocom (DOT) ru[/email] (Vitaly Repin) writes:

Quote:
Hello!

Yes, I can introduce one "standard-compliant" way to get some
information of the exception:

void log_exception_info() throw() {
try {
throw;
} catch (std::exception& e) {
logg(Lvl_error, "Exception what() = %s", prefix, e.what());
logg(Lvl_error, "exception RTTI: %s", prefix,
typeid(e).name());
} catch (...) {
logg(Lvl_error, "There is no information about that exception,
} sorry");
}
};

You simply re-generate the last exception.

I am not sure if i understand correctly: this is the handler set via
set_unexcpected?

cu!

christoph


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Vitaly Repin
Guest





PostPosted: Mon Oct 18, 2004 5:27 pm    Post subject: Re: unexpected shame^w exception Reply with quote

Hello!

[email]news (AT) pgxml (DOT) net[/email] wrote in message news:<87zn2m1qro.fsf (AT) gandalf (DOT) pgxml.net>...
Quote:
You simply re-generate the last exception.

I am not sure if i understand correctly: this is the handler set via
set_unexcpected?

This function can be executed from the handler of unexpected exceptions.

Good bye!
--
WBR & WBW, Vitaly

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
John Torjo
Guest





PostPosted: Mon Oct 18, 2004 7:03 pm    Post subject: Re: unexpected shame^w exception Reply with quote

Quote:
I really don't think you've provided us with enough information to do
any judgement. Could you be a little more specific?

Hm.. no. I think it should be less specific. The problem is not that
stream that threw that exception (code that i will throw away anyway), i
am looking for means to deal with unexpected exceptions. Just terminate
a program without any information why cant be it. What if you linked
against a third party lib that throws something unkown?


If it's unexpected, how can you deal with it Wink ?

Now seriously, IMO a well-behaved exception class should derive from
std::exception. Thus, you can catch std::exception, and at least
report the .what() string.
And catch(...), and report something like "unexpected exception".

Best,
John


John Torjo, Contributing editor, C/C++ Users Journal
-- "Win32 GUI Generics" -- generics & GUI do mix, after all
-- http://www.torjo.com/win32gui/
-- v1.5 - tooltips at your fingertips (work for menus too!)
+ bitmap buttons, tab dialogs, hyper links, lite html

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Tue Oct 19, 2004 5:58 pm    Post subject: Re: unexpected shame^w exception Reply with quote

[email]jtorjo (AT) yahoo (DOT) com[/email] (John Torjo) wrote in message
news:<c638aac5.0410180932.1e213580 (AT) posting (DOT) google.com>...
Quote:
I really don't think you've provided us with enough information to do
any judgement. Could you be a little more specific?

Hm.. no. I think it should be less specific. The problem is not
that stream that threw that exception (code that i will throw away
anyway), i am looking for means to deal with unexpected
exceptions. Just terminate a program without any information why
cant be it. What if you linked against a third party lib that
throws something unkown?

If it's unexpected, how can you deal with it Wink ?

Now seriously, IMO a well-behaved exception class should derive from
std::exception. Thus, you can catch std::exception, and at least
report the .what() string.

I'd also output something like typeid( exception ).name().

Quote:
And catch(...), and report something like "unexpected exception".

It's rather a shame that you can't at least find out the type, given
that the system must know it.

--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
news@pgxml.net
Guest





PostPosted: Wed Oct 20, 2004 6:34 pm    Post subject: Re: unexpected shame^w exception Reply with quote

Hi!

I mix two answers in this posting. ;-)

[email]kanze (AT) gabi-soft (DOT) fr[/email] writes:

Quote:
jtorjo (AT) yahoo (DOT) com (John Torjo) wrote in message

[...]

Quote:
Hm.. no. I think it should be less specific. The problem is not
that stream that threw that exception (code that i will throw
away anyway), i am looking for means to deal with unexpected
exceptions. Just terminate a program without any information why
cant be it. What if you linked against a third party lib that
throws something unkown?

[...]

Quote:
Now seriously, IMO a well-behaved exception class should derive from
std::exception. Thus, you can catch std::exception, and at least
report the .what() string.

Yes... but: in case of doubt the information reported by what() has a
value close to zero[1].

Quote:
I'd also output something like typeid( exception ).name().

Yes.. neat... nice. But this is not the way to enlightenment in the
end. (in my very humble opinion)

Quote:
And catch(...), and report something like "unexpected exception".

It's rather a shame that you can't at least find out the type, given
that the system must know it.

Yepp. So now, "bring out the dead" and let us see what can be done at
least to the stuff that is compiled on our own machines.

I think of [2] having std::exception inherit a class that can tell
from where the exception comes (compilation unit, method/function,
linenumber)... hm... iam not the first one who has dark thoughts like
these?

[x] <-- fill in your input here.

cu,

christoph

Footnotes:
[1] i am no native english speaker; in german it would be "der
Informationsgehalt geht gegen Null"

[2] yes.. drity.. depends on the compiler... violates standard.. i
know.



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
John Torjo
Guest





PostPosted: Wed Oct 20, 2004 9:38 pm    Post subject: Re: unexpected shame^w exception Reply with quote

Quote:

I'd also output something like typeid( exception ).name().

True. That's a bliss with VC71. A less of a bliss with gcc, however...

Quote:

And catch(...), and report something like "unexpected exception".

It's rather a shame that you can't at least find out the type, given
that the system must know it.

True... It would be great if the compiler would do us a favor, and
wrap it up as a C++ std::exception derived exception ;)

Best,
John

John Torjo, Contributing editor, C/C++ Users Journal
-- "Win32 GUI Generics" -- generics & GUI do mix, after all
-- http://www.torjo.com/win32gui/
-- v1.5 - tooltips at your fingertips (work for menus too!)
+ bitmap buttons, tab dialogs, hyper links, lite html

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Alberto Barbati
Guest





PostPosted: Thu Oct 21, 2004 5:14 pm    Post subject: Re: unexpected shame^w exception Reply with quote

[email]kanze (AT) gabi-soft (DOT) fr[/email] wrote:
Quote:

And catch(...), and report something like "unexpected exception".

It's rather a shame that you can't at least find out the type, given
that the system must know it.


It would be nice to have:

catch(auto& e)
{
//...
}

isn't it? ;-)

Alberto

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Thu Oct 21, 2004 5:31 pm    Post subject: Re: unexpected shame^w exception Reply with quote

[email]jtorjo (AT) yahoo (DOT) com[/email] (John Torjo) wrote in message
news:<c638aac5.0410192321.6490cdd7 (AT) posting (DOT) google.com>...

Quote:
I'd also output something like typeid( exception ).name().

True. That's a bliss with VC71. A less of a bliss with gcc, however...

I've not tried it with VC++, but from what I've seen, g++ seems to be
amongst the worse here. Even Sun CC is better.

Quote:
And catch(...), and report something like "unexpected exception".

It's rather a shame that you can't at least find out the type, given
that the system must know it.

True... It would be great if the compiler would do us a favor, and
wrap it up as a C++ std::exception derived exception Wink

I'm not really that much in favor of wrapping, although I suppose with a
templated derived type, it would be a solution. But what I was really
thinking of was something much simpler, along the lines, say, of a
standard function:

typeid const& get_current_exception() ;

I'm pretty sure that the implementation must have this information at
hand, otherwise, how could throw (without an argument) work?

--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Frank Birbacher
Guest





PostPosted: Sun Oct 24, 2004 2:45 pm    Post subject: Re: unexpected shame^w exception Reply with quote

Hi!

Alberto Barbati wrote:
Quote:
It would be nice to have:

catch(auto& e)
{
//...
}

isn't it? Wink

or maybe:

try{
//...
}
template<typename T>
catch(T& e)
{
//access typeid(T)
}

;) and maybe specialize it

Frank


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.