• Post Reply Bookmark Topic Watch Topic
  • New Topic

try in exception  RSS feed

 
Gaurav Pavan Kumar Jain
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks

Please help me to know in which condition try block will not be executed in exception handling

Example:-
try{
\\ block will not be executed in which conditions
}
catch{
\\ some code here
}
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gaurav,

Your question is obscure but here what you could ask:

In what cases catching certain exception is not ok, until the try block throws it? OK? If this is your question here you go:

1- If the you catch any subclass of Exception class, except subclasses of RuntimeException, you must throw that exception in the try block.
2- Even if you declare that exception in the method, but you catch it too, your code must throw that exception in the try block, otherwise code wont compiler.
3- RuntimeException (itself and its subclasses), you can throw it without putting try catch block or without declaring it in the method.


Regards,
cmbhatt
 
raj malhotra
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put try block in if condition and that if condition if returns false then try block will not excute.
 
Gaurav Pavan Kumar Jain
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Raj
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!