@throws in Scala

I use Eclipse for programming in Scala, but it gives me an error when I use annotation @throws.

import org.newdawn.slick.AppGameContainer
import org.newdawn.slick.BasicGame
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
import org.newdawn.slick.SlickException
import scala.throws

object Base extends BasicGame("SNAKE!")
{  
  def main(args: Array[String]) 
  {
      println("Starting up")
  }

  def init(container : GameContainer)
  {
    @throws(classOf[SlickException])
  }

}
+5
source share
1 answer

@throwsas you wrote is a Scala annotation which annotates the method and explicitly declares that this method may throw an exception of the declared type (or subclass). Annotations are meta-information about the declaration. As in Java, the annotation belongs immediately before the method declaration. You can read a little more about Scala annotations here:

http://www.scala-lang.org/node/106

, : Scala, Java, @throws , Java , , RuntimeException .

: Scala, throw new SlickException.

+13

All Articles