简体   繁体   English

在 Dart 中抛出没有堆栈跟踪的异常

[英]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.

相关问题 Dart 未处理异常:对空值使用的空检查运算符,堆栈跟踪: - Dart Unhandled Exception: Null check operator used on a null value, stack trace: Dart 未处理的异常:Null 检查运算符用于 null 值,堆栈跟踪:#0 - Dart Unhandled Exception: Null check operator used on a null value, stack trace: #0 Dart 未处理的异常:连接失败,堆栈跟踪:#0 IOClient.send(包:http/src/io_client.dart:88:7) - Dart Unhandled Exception: Connection failed, stack trace: #0 IOClient.send (package:http/src/io_client.dart:88:7) 如何在 Crashlytics/Flutter (Android) 中查看 Dart 代码堆栈跟踪而不是 Java 代码堆栈跟踪 - How to see Dart code stack trace instead of Java code stack trace in Crashlytics/Flutter (Android) 如何获取 Dart 隔离错误的完整堆栈跟踪 - How to get full stack trace of Dart Isolate error 如何根据flutter dart中的if else检查块抛出异常 - How to throw an exception based on if else check blocks in flutter dart Flutter Firebase Crashlytics 将堆栈跟踪报告为 Java 类文件而不是 Dart 文件 - Flutter Firebase Crashlytics reports stack trace as Java class files and not as Dart files 没有颤动框架堆栈跟踪 - No flutter framework stack trace 为什么 dart 没有抛出编译时错误类型的异常。 运行时? - why dart didn't throw compile-time mistype exception instead. of run-time? Dart 堆栈跟踪都以 3/7/b/f(ARM 架构)结尾,而我们知道 ARM/Thumb/Thumb(2) 指令是 2 或 4 个字节 - 这怎么会发生? - Dart stack trace all ends with 3/7/b/f (ARM architecture), while we know ARM/Thumb/Thumb(2) instructions are 2 or 4 bytes - How can that happen?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM