[英]Throw exception without stack trace in Dart
When you throw an exception in Dart (assuming you don't catch it) the program execution will end showing you the exception and the stack trace.当您在 Dart 中引发异常时(假设您没有捕获它),程序执行将结束,向您显示异常和堆栈跟踪。 I was wondering if there is any way to do it but without showing the stack trace (you don't want the final user to see it) and using throw.
我想知道是否有任何方法可以做到这一点,但不显示堆栈跟踪(您不希望最终用户看到它)并使用 throw。
Note: No, I don't want to catch the expression, I want to terminate the program after throwing the exception showing a message but without the stack trace.注意:不,我不想捕获表达式,我想在抛出显示消息但没有堆栈跟踪的异常后终止程序。
Example:例子:
class MyErrors implements Exception{
var notInt;
MyErrors(this.notInt);
}
void main(List<String> args) {
var myErrors = MyErrors("The input wasn't an int, please restart the program");
throw myErrors.notInt
}
Why not just have main()
be a giant try/catch, with the rest of your program called from try, and the catch block logging the error/stacktrace for smart people to review, and perhaps the finally block to restart the app?为什么不让
main()
成为一个巨大的 try/catch,从 try 调用程序的 rest,并且 catch 块记录错误/堆栈跟踪以供聪明的人查看,也许 finally 块来重新启动应用程序?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.