Bookmark Topic Watch Topic
  • New Topic

what will happen when following case raised while creating connection object  RSS feed

 
Praveen palukuri
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Report post to moderator
hi,
please give the solution to my query.

Generally we write code in try block for creating connection and closing these objects in finally block.
There is a situation like an exception is raised while creating connection object so that object is not created but the statements in finally block(closing these objects) are executed.

What will happen at this situating connection object is not created but still it tries to close?
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Report post to moderator
A NullPointerException...
You have to check if the connection is ok before closing it. (or do the close op in another try/catch block)
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Report post to moderator
Less talk, more code:

Does that answer your question?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't cross post
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!