Re: [[gtkmm] Alternate libglademm interface]
- From: joey yandle <jwy divisionbyzero com>
- To: Christer Palm <palm nogui se>
- Cc: gtkmm-list gnome org
- Subject: Re: [[gtkmm] Alternate libglademm interface]
- Date: Tue, 7 Oct 2003 18:50:50 -0700 (PDT)
>
> throw specifiers are actually used in Glib, so they shouldn't cause any
> porting issues that are not already there. Personally I love them - they
> definitely help to improve your code quality.
>
I find throw() clauses in c++ to be worse than useless, and do nothing to
improve code quality. Check out the following code:
========
#include <exception>
#include <iostream>
class foo_exception : public std::exception {
public:
virtual const char* what() const throw() { return "foo"; }
};
class bar_exception : public std::exception {
public:
virtual const char* what() const throw() { return "bar"; }
};
void foo() throw(foo_exception) {
throw bar_exception();
}
int main(int argc, char** argv) {
try {
foo();
} catch(std::exception& e) {
std::cout << e.what() << std::endl;
}
return 0;
}
==========
As you would expect, the throw() clause guarentees that foo() will only
throw foo_exception. However, when bar_exception is thrown, the app
abort()'s, because it can't throw() it.
In Java, this code wouldn't compile; the compiler would insist on
foo() either catching or throwing bar_exception. But in c++, this isn't
the case. So by putting a throw() clause, we've guarenteed that the app
will abort if presented with an exception not in the throw clause. I
find this to be extremely bad ;(
cheers,
--
If video games really affected kids, we'd all be running around in dark
rooms, munching on pills, and listening to electronic music.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]