Domani Tomlindo
Domani Tomlindo

Reputation: 249

Java - Catch Exception e

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!");

Upvotes: 5

Views: 17742

Answers (2)

Jose Ortega
Jose Ortega

Reputation: 24

It is a object which contain info about an error happend. Inherit from throwable and give you a clear message of why your code went wrong

More info

enter link description here

enter link description here

Upvotes: 1

Elliott Frisch
Elliott Frisch

Reputation: 201507

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();
}

Upvotes: 10

Related Questions