本文介绍了飞镖中的自定义例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我已经编写了这段代码来测试自定义异常在dart中的工作方式。I have written this code to test how custom exceptions are working in dart.我没有得到想要的输出,有人可以解释一下如何处理吗?I'm not getting the desired output could someone explain me how to handle it??void main(){ try { throwException(); } on customException { print("custom exception is been obtained"); }}throwException(){ throw new customException('This is my first custom exception');}推荐答案您可以看一下 Dart语言之旅中的href = http://www.dartlang.org/docs/dart-up-and-running/ch02.html#exceptions rel = noreferrer>例外部分 。You can look at the Exception part of A Tour of the Dart Language.以下代码按预期方式工作(已获得自定义异常显示在控制台):The following code works as expected (custom exception is been obtained is displayed in console) :class CustomException implements Exception { String cause; CustomException(this.cause);}void main() { try { throwException(); } on CustomException { print("custom exception is been obtained"); }}throwException() { throw new CustomException('This is my first custom exception');} 这篇关于飞镖中的自定义例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS!
05-23 15:43