• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime Exception (Wrap IOException)

 
Shay banon
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The interface that was provided doesn't support IO Exception being thrown. I decided to create a DataAccessExceptinon which is a runtime exception, that acts as a wrapper for the IOException.
I also have a service layer, but I decided to let the exception be propagated to the gui layer. The reason for that is that if the actual data level implementation will be changed (i.e. database) the system will remain the same, and the DataAccessException will wrap the SQLException.
The problem is that SUN advises against it (though recent movement are all forward - big debate, don't ask :-). Will they allow it? I'm documenting it and all...

Please help, I want to submit it soon...

Cheers, Shay
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shay,

Welcome to JavaRanch and this forum.

Lots of candidates have wrapped the IOException in their own RuntimeException and passed, so you should be able to as well.

Regards, Andrew
 
Yanxin Zhao
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi: Andrew
so did what you said mean that I can change the DB interface? I mean throw IOException in which Interface.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yanxin,

No, I strongly advise against changing the DB interface.

If you choose to wrap the IOException inside your own RuntimeException, then you will not need to declare any extra exceptions in your method signature.

Regards, Andrew
 
Yanxin Zhao
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi: Andraw
thanks for your reply.
I do not really know what does you said meaning ? yes, I want to wrap IOException in my own RuntimeException, I also want to send this exception to GUI. but I could not throw RuntimeException to GUI, I if do not change which given interface.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yanxin,

Here is some sample code to get you thinking:



As you can see, aMethod() does not declare any exceptions. Do you see how this might work in your situation?

My main() method can still catch the exception, even though it is not declared in the method signature of the method being called.

I did not use the "Throwable" parameter in the constructor of MyException, but I put it in there to make sure you are aware of it - you would probably want to use this when wrapping the IOException.

Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic