I am writing a small library, and in which I need to access several different type of files. While the access method itself is different for each kind of file format, they seem to have a lot in common, and I put an interface in the class hierarchy, in which I wrote a method that should connect to the data source.
However, since the data source might be protected by password and/or user permission, sometimes it need authentication to retrieve the data. My questions are:
AuthenticationException
SecurityException
Since it's your own API, you might create your own Exception to go with it, which can carry the details... There's no requirement or benefit to using the Java exception that "sounds closest to" your exception.
I personally find that peppering my code with try/catch blocks is... tedious and unsightly. So I try to make API's that don't require it.
In your case, maybe you could provide queries so your API clients could preflight the actions, and their usage might look something like:
Thing t = new Thing(...);
if(t.needsAuth())
{
boolean ok = t.doPassword("abc123");
if(!ok)
log("wrong password");
}
boolean did= t.doIt();
if(!did)
log("sorry: " + t.getProblem());