调用超级构造函数 [英] Call Super Constructor

查看:47
本文介绍了调用超级构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义异常类,如下所示:

I have a custom exception class like the following :

case class CustomException(errorMsg:String)  extends Exception(error:String)

当我捕获异常时,我所需要的只是抛出我的自定义异常并将我的错误消息传递给自定义异常.我希望从 CustomException 构造函数调用 super(errMsg)但是,这不是现在发生的事情,我遇到了编译错误.

All what I need that when I catch exception is to throw my custom exception and pass my error message to the custom exception . I expect from CustomException constructor to call super(errMsg) However , this isn't what goes now and I got a compilation error .

 catch {
      case s: Exception => throw CustomException("This is a custom message")
    }

如何调用超级构造函数:

How could I call the super constructor :

super(errorMessage)

推荐答案

case class CustomException(errorMsg:String)  extends Exception(errorMsg)

这篇关于调用超级构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆