[#575] | project: compiler | priority: low | category: bug | |
---|---|---|---|---|
submitter | assigned to | status | date submitted | |
Sean | Nikolay | fixed | 2006-04-25 16:04:15.0 | |
subject | Checked exceptions broken when calling Scala from Java | |||
code |
example java code: try { file.read(); } catch (IOException e) { ... } |
|||
what happened | "read()" is implemented in Scala. Above code does not compile because checked exceptions can only be caught if they are specified to be thrown. Be\ cause Scala does not generate throw information, checked exceptions can never be caught when calling Scala metho\ ds (have to catch Throwable). |
|||
what expected | Not sure. This is a hard issue to fix. I guess calling Scala from Java is just a very tricky thing to do. Better to not mix the languages as much as possible (try not to call Scala libraries from Java). | |||
[back to overview] |
Martin edited on 2006-04-26 11:37:53.0 |
As Nik suggests, I think this is a case for attributes. something like [throws[java.io.IOException]] def read() = ... where `throws' is an attribute class, defined as follows: class throws[T <: Throwable] extends Attribute We should define this attribute and translate it into a throws clause. If there are several exceptions thrown, we can express this by several `throws' attributes, i.e. [throws[A], throws[B]] def foo() = ... Nik, do you want to do this (maybe with the help of Iulian)? |
Nikolay edited on 2006-05-19 17:03:42.0 |
Added an attribute - scala.throws(exc: Class) - to specify the exceptions thrown by a method:
[throws(classOf[java.io.IOException]),
throws(classOf[java.io.FileNotFoundException])]
def read() = ...
|