Created
June 25, 2013 23:41
-
-
Save gaul/5863490 to your computer and use it in GitHub Desktop.
Exception catch order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Demonstrate that exception catch order is relevant and javac warns when | |
* catching a more specific exception after a less specific one: | |
* | |
* CatchOrder.java:20: exception java.io.FileNotFoundException has already been caught | |
* } catch (FileNotFoundException fnfe) { | |
* ^ | |
* 1 error | |
*/ | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
public class CatchOrder { | |
public static void main(String[] args) { | |
try { | |
throw new FileNotFoundException(); | |
} catch (IOException ioe) { | |
System.out.println("caught IOException"); | |
} catch (FileNotFoundException fnfe) { | |
System.out.println("caught FileNotFoundException"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment