无法识别抛出注释
Throws annotation is not recognised
我试图表明一个方法可以抛出异常。我使用了 throws 注释,但编译器向我显示警告:
[warn] /root/playit/app/entities/game/GameRepository.scala:67: Tag '@throws(classOf[DatabaseException])' is not recognised
[warn] /**
[warn] ^
代码如下:
/**
* @throws(classOf[DatabaseException])
*/
def insert(game: Game): Long = {
...
}
我不知道我做错了什么。 IDE 表示 "Missing tag parameter"。我正在使用 Play 2.4 和 IntelliJ IDE。
您将 Scala @throws
注释与 Scaladoc @throws
标记混淆了。
注解直接在方法上,实际编译成字节码(像Java中的throws
关键字),Scaladoc变成文档(比如什么情况下异常被抛出)。
/**
* @throws DatabaseException Banana banana.
*/
@throws(classOf[DatabaseException])
def insert(game: Game): Long = {
...
}
编辑添加:
这种语法结合了两者,看起来更适合我:
@throws[DatabaseException]("Banana banana.")
def insert(game: Game): Long = {
...
}
我试图表明一个方法可以抛出异常。我使用了 throws 注释,但编译器向我显示警告:
[warn] /root/playit/app/entities/game/GameRepository.scala:67: Tag '@throws(classOf[DatabaseException])' is not recognised
[warn] /**
[warn] ^
代码如下:
/**
* @throws(classOf[DatabaseException])
*/
def insert(game: Game): Long = {
...
}
我不知道我做错了什么。 IDE 表示 "Missing tag parameter"。我正在使用 Play 2.4 和 IntelliJ IDE。
您将 Scala @throws
注释与 Scaladoc @throws
标记混淆了。
注解直接在方法上,实际编译成字节码(像Java中的throws
关键字),Scaladoc变成文档(比如什么情况下异常被抛出)。
/**
* @throws DatabaseException Banana banana.
*/
@throws(classOf[DatabaseException])
def insert(game: Game): Long = {
...
}
编辑添加:
这种语法结合了两者,看起来更适合我:
@throws[DatabaseException]("Banana banana.")
def insert(game: Game): Long = {
...
}