• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another Q On Exception Handling!

 
Vikas Sood
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I am writing the design choices document at the moment.An happen to come across the SCJD checklist which states something like this:
If any method like getRecord() returns null, is it being appropriately handled ?

I have only made arrangement for handling Remote and Database exception in my implementation.Should i also ahve an catch clause like:
catch(Exception ex){
.......
}
for the above kind of scenario.
Kindly Comment.
VikasSood
 
S. Ganapathy
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vikas,
getRecord() method will never return null. If the record is not found, record not found exception is thrown. so there is no chance for nullpointer exception. ioexception may occur, but, that can be chained or wrapped in record not found exception.
Which assignment are you doing? Contractor, or Hotel?
Regards,
Ganapathy.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vikas,
I would advise against catching Exception - there are some subclasses of it that are not really meant to be caught. Only catch those exceptions that you believe you can handle.
I think the check point is valid - in any method you have written or call, can it return null? This is different from the method throwing an exception. Normally you would want to handle the fact that null was returned, not wait until you tried to work with the (non existant) returned data which might then cause an exception to be thrown.
So - can any of the methods you wrote, or inherited from the provided Data class, or use in the standard API return null? And do you handle that?
Regards, Andrew
 
Vikas Sood
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Andrew
I have another question on the above topic.Thre i noprovision for corrupted database file,that is what i tried today, i removed around 5 characters from the database file and tried to check am i able to handle the exception caused, but as the Data class just worries about the IO and DatabaseException and change in db.db causes NullPointerException, i have a scenario where client when started with corrupted database file throws the exception and hangs. Do i need to take into account such a scenario.
Kindly comment.
I am at the final stages now, writting Design.txt and uploading on Monday and taking exam on Tuesday.
Thans and Regards,
VikasSood
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know it would matter in the real world. But you do not need to concern yourself with someone removing 2 bytes from the data file and your application having to handle this problem.
I did not code for this and I haven't heard of anyone else coding for this in their assignment.
Mark
 
Vikas Sood
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark,
You cant imagine my respite at this late juncture in not having to alter my implementation.
Regards,
VikasSood
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic