Re: should we call exit() inside exceptional catching blocks
On 3=D4 26=C8=D5, =CF =CE=E75=CA=B128=B7=D6, "Alexander Block" <abloc..=
..@googlemail.com> wrote:
On 26 Mrz., 11:23, "lovecreatesbea...@gmail.com"
<lovecreatesbea...@gmail.com> wrote:
Is the following code (without any code at lines x and x + 3) correct?
Is it better to call exit() or re-throw the exceptions at line x and
line x + 3?. What is the better code should we place at line x and
line x + 3?
try {
cnn = env->createConnection(user, pwd, db);} catch (SQLException =
&esql){
cerr << "DB Exception: " << esql.getMessage();
/* line x ? */} catch (exception &e){
cerr << "Exception: " << e.what();
/* line x + 3 ? */
}
/*more code*/
If it's a critical exception that stops the execution of your
application,
why do you catch it here? You should have a try/catch
statement in your lowest application level (your main function for
example)
Thank you. Please correct me if I misunderstand the knowledge.
Placing exception handling code in the main() function and without
placeing them in other called functions makes the code more cleaner
and simpler.
... that catches all uncaught exceptions.
But still place some special exception handling code for special non-
main() function? Doesn't this conflicts with the rule above?
This allows all
destructors in the stack to be called and makes it possible to
gracefully clean up everything.
Does this relate to object scope things?