One thing to keep in mind: if you are using the IntelliJ IDE, just a simple copy/paste of Java code can convert it to Kotlin.
现在来回答你的问题.如果您想创建自定义异常,只需扩展Exception类,如下所示:
class TestException(message:String): Exception(message)
然后像这样扔出go :
throw TestException("Hey, I am testing it")