• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DatabaseException question

 
Fred Barnes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
I was looking at the Data class and all the methods that throw DatabaseExceptions are due to possible IOException problems.
My questions is why doesn't Database exception extend IOException instead of Exception? That way you can only throw IOException in you DataInterface.
What are your opinion about this?
Regards
Fred
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My questions is why doesn't Database exception extend IOException instead of Exception? That way you can only throw IOException in you DataInterface.

The goal is not to shorten the list of exceptions by throwing only a single generic exception, but to be able to catch different types of exceptions and process them based on their type.
Eugene.
 
Fred Barnes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eugene,
Thank you for your reply.
I do understand the point you made, but what advantage is DatabaseException gaining from extending from Exception instead of IOException?
In this specific excample would it not be better to make DatabaseException extend IOException?


Regards
Fred
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I do understand the point you made, but what advantage is DatabaseException gaining from extending from Exception instead of IOException?

The DatabaseException is thrown when there is some logical (rather than I/O) error, such as an attempt is made to add a duplicate key. If you make DatabaseException a subclass of IOException, it will be misleading, because it will suggest a different type of problem. To make this point a bit more dramatic, suppose that you create your own exception class to deal with the server availability problems. You could subclass an ArrayIndexOutOfBoundsException and throw it to indicate that the server is down, and it will work, but how much sense does it make?
Eugene.
[ December 23, 2002: Message edited by: Eugene Kononov ]
 
Fred Barnes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eugene,
Thank you for your reply.
Regards
Fred
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Eugene. I also learn something new.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic