I have a Query regarding try-catch-finally clauses.
In most of the books ,its mentioned that try must have ,catch or finally block .
try can work without catch with finally .
But i tried some programs ,i observed ,For checked Exceptions ,
try must have catch ,even if finally is there ,else Compiler errors.
but in case of unchcked expcetions,lik RuntimeException ,catch can be omitted,Reason is obvious .JVM handles it but not to Checked case.
My question is : Is that so ,am i getting right ,If its right ,its not mentioned anywhere .Only thing book'-people write is about try-catch or finally thing .
i wirte here a code template to make myself more clear
try
{ throw new Exception(); //checked
}catch(Exception e){} //if omitted .compiler error
finally{}
but for Runtime /unchecked case:
try
{
throw new RunTimeException(); //works without catch,
}finally{}
thanks
In most of the books ,its mentioned that try must have ,catch or finally block .
try can work without catch with finally .
But i tried some programs ,i observed ,For checked Exceptions ,
try must have catch ,even if finally is there ,else Compiler errors.
but in case of unchcked expcetions,lik RuntimeException ,catch can be omitted,Reason is obvious .JVM handles it but not to Checked case.
My question is : Is that so ,am i getting right ,If its right ,its not mentioned anywhere .Only thing book'-people write is about try-catch or finally thing .
i wirte here a code template to make myself more clear
try
{ throw new Exception(); //checked
}catch(Exception e){} //if omitted .compiler error
finally{}
but for Runtime /unchecked case:
try
{
throw new RunTimeException(); //works without catch,
}finally{}
thanks