• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in java  RSS feed

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If we will not close resource in finally block will it throw exception?if it throw then which exception will be thrown?
 
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i guess you mean closing of connections. It will not throw any exceptions but it is always a good practice to close connection in a finally block.
 
priyanaka jaiswal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ashwin,

Does finally block throws exception?
 
Ranch Hand
Posts: 148
Hibernate Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi priyanaka ,

If you are not closing resource in finally block ,then it wont throw any exception.But it is good practice to
close any resource after checking the null condition.

if it throw then which exception will be thrown?


This is entirely depends upon the checked exception declared in the method syntax.

for eg.



Thanks
 
priyanaka jaiswal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
priyanaka jaiswal wrote:Hi Ashwin,

Does finally block throws exception?


you should try this whether it will throws or not
 
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try something like this... and see what happens when you compile it.
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Especially what will happen when the file does not exist.

Ashwin Sridhar wrote:i guess you mean closing of connections. It will not throw any exceptions

Vijay Tidake wrote:If you are not closing resource in finally block ,then it wont throw any exception.

Not directly, no. But it's quite possible, in server environments even probable, that the operating system will reach the limit of open files / connections, and opening a new file / connection will result in an exception.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!