File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Try/catch flow??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Try/catch flow???" Watch "Try/catch flow???" New topic

Try/catch flow???

srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252

i have a couple of doubts :
1)do method m1() has to use throws clause in its definition ...if not why ...since You are not using try,catch also..
2) can we catch the runtime exceptions since indexArrayOutOfBoundsExcpetion is a runtime exception as well as NullPointerException..
3)can anyone explain me the flow,since we have used return here do the finally block will be exceuted and also whether END will be printed .

thanks & regards


Thanks & Regards<br /> <br />-Srikanth
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
The concept goes this way. You have to handle all Checked Exception either using try catch or using throws clause. "IndexOutOfBoundsException" is an Runtime exception and not checked exception, compiler wont complain that you haven't handled it but at run time your program will terminate if it's not handled.

A try clause should be accompanied either by a catch or finally class even both are ok. When an exception is throws the catch clause gets executed followed by th finally. the finally will be executed even if the exception is not thrown.

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Andreas Sandberg
Ranch Hand

Joined: Sep 14, 2005
Posts: 31
But, you can catch runtime exceptions. The question is whether or not it makes sense too.

"When the compilers not happy ain't nobody happy"
I agree. Here's the link:
subject: Try/catch flow???
It's not a secret anymore!