'How to allow @throws for val(s) in Scala?

I have legacy Scala code to upgrade from 2.13.3 version to 2.13.8 version. During the upgrade, I am facing the following error:

On line 2: error: `@throws` only allowed for methods and constructors

The error is occurring due to @throws not allowed for val. The code is as follows:

scala> @throws(classOf[Exception])
     | val a: Int = 1
       val a: Int = 1
           ^
On line 2: error: `@throws` only allowed for methods and constructors

Hence, how can I allow @throws for val in Scala 2.13.8.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source