question about exceptions



 DEVELOP > c-Plus-Plus > question about exceptions

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "jcc"
Date: 10 May 2006 05:54:03 AM
Object: question about exceptions
If I use a third-party library, and I don't know if it will throw
exception. Will it crash my program if I do not catch exception and
some exception occurs in the library?
.

User: "flopbucket"

Title: Re: question about exceptions 10 May 2006 07:05:14 AM
You can use catch(...) to catch everything, i.e.:
try
{
thirdpartylib->method();
}
catch(...)
{
cerr << "3rd party lib threw exception" << endl;
}
otherwise the c++ runtime will eventually call unexpected() which i
believe defaults to calling abort() which is probably not what you
want.
Also check the 3rd party library, source if available or documentation,
and then you can find out what exceptions actually may be thrown.
.

User: "=?ISO-8859-1?Q?Stefan_N=E4we?="

Title: Re: question about exceptions 10 May 2006 06:06:40 AM
jcc schrieb:

If I use a third-party library, and I don't know if it will throw
exception. Will it crash my program if I do not catch exception and
some exception occurs in the library?

Well...
If you don't catch the exception, 'uexpected()' will get called, which
in turn calls 'terminate()' by default.
Doesn't the documentation of the library say if and which exception
might get thrown ?
/S
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
.

User: ""

Title: Re: question about exceptions 10 May 2006 06:20:01 AM
jcc wrote:

If I use a third-party library, and I don't know if it will throw
exception. Will it crash my program if I do not catch exception and
some exception occurs in the library?

If the library doesn't document the exceptions it may throw, or you
don't trust it, you can use the following catch-all (pun intended):
try {
untrusted_library_call();
}
catch( ... ) { // Catch everything
// Error handling
}
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER