Skip to content

Instantly share code, notes, and snippets.

@gaul
Created June 25, 2013 23:41
Show Gist options
  • Save gaul/5863490 to your computer and use it in GitHub Desktop.
Save gaul/5863490 to your computer and use it in GitHub Desktop.
Exception catch order
/**
* 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