public class ThrowException {
public static void main(String[] args) {
try {
foo();
}
catch(Exception e) {
if (e
Maybe this helps...
Note the cleaner way to catch exceptions in the example below - you don't need the e instanceof IOException
.
public static void foo() throws IOException {
// some code here, when something goes wrong, you might do:
throw new IOException("error message");
}
public static void main(String[] args) {
try {
foo();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}