| 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
}
.
|
|
|
|

|
Related Articles |
|
|