Finally is always executed : Exceptions « Language Basics « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Language Basics » ExceptionsScreenshots 
Finally is always executed
Finally is always executed


// : c09:AlwaysFinally.java
// Finally is always executed.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.

class FourException extends Exception {
}

public class AlwaysFinally {

  public static void main(String[] args) {
    System.out.println("Entering first try block");
    try {
      System.out.println("Entering second try block");
      try {
        throw new FourException();
      finally {
        System.out.println("finally in 2nd try block");
      }
    catch (FourException e) {
      System.err.println("Caught FourException in 1st try block");
    finally {
      System.err.println("finally in 1st try block");
    }
  }
///:~


           
       
Related examples in the same category
1. Illustrate various Exceptions Illustrate various Exceptions
2. Experience exceptionsExperience exceptions
3. StackTrace
4. What happens if a method declares an unchecked exception?
5. Simple demo of exceptionsSimple demo of exceptions
6. Simple demo of exceptions, with finally clauseSimple demo of exceptions, with finally clause
7. ThreadBasedCatcher - Demonstrate catching uncaught exceptions
8. Exception CatcherException Catcher
9. Turning off Checked exceptions
10. Demonstrates exception chainingDemonstrates exception chaining
11. Demonstrating the Exception MethodsDemonstrating the Exception Methods
12. Further embellishment of exception classesFurther embellishment of exception classes
13. The finally clause is always executedThe finally clause is always executed
14. Your own Exception classYour own Exception class
15. Catching exception hierarchiesCatching exception hierarchies
16. How an exception can be lost
17. Exception in main method
18. Ignoring RuntimeExceptionsIgnoring RuntimeExceptions
19. Demonstrating fillInStackTrace()Demonstrating fillInStackTrace()
20. Rethrow a different object from the one that was caughtRethrow a different object from the one that was caught
21. Inheriting your own exceptionsInheriting your own exceptions
22. Overridden methods may throw only the exceptions
23. Throw Exception OutThrow Exception Out
w___ww.j___av_a__2__s_._co__m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.