question about exceptions

J

jcc

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?
 
?

=?ISO-8859-1?Q?Stefan_N=E4we?=

jcc said:
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
 
C

cbmanica

jcc said:
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
}
 
F

flopbucket

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top