Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Try/catch flow???

 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

srikanth
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Srikanth,
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.
 
Andreas Sandberg
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But, you can catch runtime exceptions. The question is whether or not it makes sense too.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic