Brandon Sloane created DAFFODIL-2287:
----------------------------------------
Summary: JApi throws checked exceptions without declaring
Key: DAFFODIL-2287
URL: https://issues.apache.org/jira/browse/DAFFODIL-2287
Project: Daffodil
Issue Type: Bug
Components: API
Affects Versions: 2.5.0
Reporter: Brandon Sloane
Java assumes that all exceptions thrown by a function are either declared in
the function signature, or extend RuntimeException. As such, the compiler will
prevent users from catching a checked exception which is not declared in the
function signature.
The Java API defines a parse function which does not declare any exceptions.
However, this function can throw a NotYetImplementedException (and possibly
other exceptions).
If a Java user attempts to catch this exception, the compiler will complain
because NotYetImplementedException is a checked exception, so Java believes it
cannot be thrown.
I suspect that this issue occurs in other places in out Java API.
The simplest solution is to make all Scala exceptions RuntimeExceptions. Since
Scala does not have checked exceptions, this is no loss to the Scala users, and
will allow Java users to treat them as normal unchecked exceptions.
The more correct solution is to go throw the java API and add throws
annotations, such as:
{quote}@throws(classOf[NotYetImplementedException]){quote}
In the meantime, users can work around this by catching Exception, and doing an
explicit instanceOf test themselves.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)