tags:

views:

253

answers:

3

Hi,

What's the difference between implicit exception and explicit exception?

If I declare catch block like: catch(Exception e). Is this implicitly declaring an exception, or explicitly?

Thanks in advance.

+1  A: 

I don't believe there's any such term as "implicit exception" or "explicit exception". Are you thinking checked and unchecked exceptions perhaps?

I've just downloaded the language specification as a PDF, and the phrases "implicit exception" and "explicit exception" don't exist anywhere within it.

Could you say where you came across the terms?

Jon Skeet
Hello Jon. There is a line in page no. 470 in Head First servlets, and the line is: "Declaring an error page for a more explicit exception." Could you please tell me what they mean with "explicit exception" here?
Greenhorn
Ah - I suspect that means "declaring an error page for a specific type of exception." In other words, you might have one error page for "anything has gone wrong" and a different one for "AuthenticationException".
Jon Skeet
More explicit in this context means for an exception type that is of a derived type (being more specific) than the more general base class type.
nojevive
A: 

I think implicitly instantiating an object is done without explicitly calling a constructor. I don't think you can do that in Java.

Example:

throw new Exception();

calls a constructor and then throws the newly created Exception object.

Jorn
A: 

Neither. Catching is not declaring an exception. Declaring an exception happens on the method:

pubic void someMethod() throws Exception.

I'm not sure what you mean by implicit vs. explicit. You probably mean something like the difference between a runtime and checked exception, but you could also a mean a method which throws a Runtime exception, which is optional.

public void someMethod() throws NullPointerException

The throws in that case is purely optional, since it is a Runtime exception, nothing should happen differently.

Yishai