Given:
3. public class Main { 4. static String s = ""; 5. public static void main(String[] args) { 6. try {/*from w ww . ja v a 2s .co m*/ 7. s += "1"; 8. throw new Exception(); 9. } catch (Exception e) { s += "2"; 10. } finally { s += "3"; doStuff(); s += "4"; 11. } 12. System.out.println(s); 13. } 14. static void doStuff() { int x = 0; int y = 7/x; } 15. }
What is the result?
H is correct.
The value of String s is 123 at the time that the divide-by-zero exception is thrown.
finally()
is not guaranteed to complete.
In this case finally()
never completes, so the System.out.println never executes.