Re: [[gtkmm] Alternate libglademm interface]



but you can redefine the unexpected( ) mechanism as follow:

#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();
}

void my_unexpected() 
{
 std::cout << "unexpected exception thrown" << std::endl;
 throw foo_exception();
}

int main(int argc, char** argv) 
{
   std::set_unexpected(my_unexpected);
   try 
   {
      foo();
   } 
   catch(std::exception& e) 
   {
      std::cout << e.what() << std::endl;
   }
   return 0;
}


On mar, 2003-10-07 at 21:50, joey yandle wrote:
> >
> > 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.
> 
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
-- 
Lic. J. Abelardo Gutierrez
Linux Counter # 80026

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/MU dx s-:++>-: a C+++ UL++++$ P++>+++ L++++>+++++ E- W+ N o K- w---(+)$
O+>- M? V? PS+ PE- Y+ PGP++ t 5 X R+ tv b++ DI(+) D++
G e++ h--- r+++ y+++
------END GEEK CODE BLOCK------

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]