Flutter Dart 尝试捕获异常行号

Moh*_*Ali 4 dart flutter

我如何知道 try, catch 中捕获的异常的行号?这是我的代码:

try{
//your code here
} catch (Exception) {
    print('Exception '+Exception.toString());

  }
Run Code Online (Sandbox Code Playgroud)

小智 7

try{
//your code here
} catch (e, stacktrace) {
    print('Exception: ' + e.toString());
    print('Stacktrace: ' + stacktrace.toString());
}
Run Code Online (Sandbox Code Playgroud)

  • 请不要仅发布代码作为答案,还要解释您的代码的作用以及它如何解决问题。带解释的答案通常质量较高,也更容易吸引点赞。 (3认同)