I have an interface
public interface DataDAO { public void doSomething() throws Exception; }
Suppose there are two implementations, one of which uses a database to retrieve data and the other that uses a Webservice.
public class DataDAOJdbc implements DataDAO { public void doSomething() throws Exception {
As you can see, the problem is creating a super general exception. Since both implementations should raise the same kind of exception.
The Jdbc implementation really only raises the possibility of a SQLException, while the Webservice implementation only raises an IOException.
The question is, how can I make the interface more elegant, so I am fixing the correct exception?
The first thing, although I created my own exception, and declare it at the interface level
public interface DataDAO { public void doSomething() throws MyCoolException; }
And then, of course, implement it.
The question is, does this make sense? I never made my own exceptions, so I'm not sure if this makes sense or not. Also, what should I consider when creating a MyCoolException?
source share