Java - Catch Exception e

Viewed 6409

What does the e mean in the following code?

try {
    // Do something
} catch (Exception e) {
    // Do something
}

I've been researching and have gotten nothing.

System.out.println("Thanks!");

2 Answers

It's a variable name. Exception is the type. e is the name. You can use a different name. You might display a message to the user (or a stack trace).

try {
    // Do something
} catch (Exception ohNo) {
    System.out.printf("Caught exception %s doing something.%n", ohNo.toString());
    ohNo.printStackTrace();
}
Related