cCss.......... said:
Consider the following code:
try
{
a=func(); // line-1
- - - -- - - - - -
- - - - - - -- - - -
}
catch(Exception e)
{
- - - - -
What is here?
}
System.out.println(a); // line-n
In the code func() returns any value to 'a'. If any exception occurs
after line-1. Would line-n print the value of a,
Yes, given as written, 'a' must have been declared outside
the try construct, 'a' will contain the result of func() after the
try/catch completes.
..or the program will
terminated after catching the exception.
A lot of this depends on "What is here?"
If it is something like..
e.printStackTrace();
..then the program will dump the stacktrace, and continue
to print the value of 'a'. OTOH, if that line is..
System.exit(int);
..then, no. The app. will terminate before printing the
result stored in/referenced by 'a'.
Note the 'caveats/ifs and buts' in the above explanation.
I would not have had to cover as many possibilities if your
code had been complete, as might be seen in an SSCCE*.
Please consider posting SSCCEs when asking questions
of this nature. In fact, now I think about it, an SSCCE would
have answered the initial question for you. The only remaining
questions might have been "Why does the example behave this
way?" or "How do I change the behaviour to..?".
* <
http://www.physci.org/codes/sscce.html>
--
Andrew Thompson
http://www.physci.org/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200801/1