我有一个自定义异常类,如下所示:
case class CustomException(errorMsg:String) extends Exception(error:String)
Run Code Online (Sandbox Code Playgroud)
当我捕获异常时,我需要的是抛出我的自定义异常并将我的错误消息传递给自定义异常.我期望从CustomException构造函数调用super(errMsg)但是,这不是现在的情况,我得到了一个编译错误.
catch {
case s: Exception => throw CustomException("This is a custom message")
}
Run Code Online (Sandbox Code Playgroud)
我怎么能调用超级构造函数:
super(errorMessage)
Run Code Online (Sandbox Code Playgroud)
Kim*_*bel 35
case class CustomException(errorMsg:String) extends Exception(errorMsg)
Run Code Online (Sandbox Code Playgroud)
case class CustomException(errorMsg:String) extends Exception(errorMsg)
Run Code Online (Sandbox Code Playgroud)
你正在调用超类的构造函数,但是你传递的参数(error)没有绑定任何东西.
| 归档时间: |
|
| 查看次数: |
11761 次 |
| 最近记录: |