user2223211 user2223211 - 6 months ago 43
Java Question

Java Exception Classes

I am new to Java and I was looking at exception handling. When we catch java exceptions, we declare and use an

of the
class without initializing it, i.e.

catch(NullPointerException e)

So my question is, how are we able to use object reference e without instantiating it?

Answer Source

They are well instantiated:

void example() {
    throw new UnsupportedOperationException("message");
}      // ^^^

void demonstration() {
    try {
    } catch (UnsupportedOperationException e) {

This very simple example should be pretty self explanatory...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download