Possible Duplicate:
define your own exceptions with overloaded constructors in scala
我想编写一个Scala异常类,该类继承Java Exception类的子类,并提供类似的构造函数(每个构造函数都调用相应的Exception ctor。即,我将如何编写与该Java类等效的Scala:
public class MyException extends java.lang.Exception {
public MyException () {
}
public MyException (String msg) {
super(msg);
}
public MyException (Throwable e) {
super(e);
}
public MyException (String msg, Throwable cause) {
super(msg, cause);
}
}
最佳答案
如何使用默认值(空)?
class YourException (msg:String=null, cause:Throwable=null)
extends java.lang.Exception (msg, cause) {}
关于java - 如何在Scala中对异常进行子类化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11011926/