Open filiph opened 4 years ago
(Never mind on the test case. I think the correct test would expect(..., completion(returnsNormally))
. If I do that, the test correctly fails. It still doesn't execute the print statements, but that seems like a distant issue to this one. So, please disregard the test. The issue with debugging, a.k.a. Instruction 1 and 2, still stands.)
I'm not sure that this is a bug. But even if it's not, I'd like to understand the following behavior so that I can explain it to users who might struggle with it. This has had pretty big influence on my productivity with Dart when debugging.
I have a project which sends error information using Sentry (an error monitoring service). Something like this:
I noticed some time ago that, in some instances, running a test in debug mode won't break on exception, and will instead break on the
rethrow
of that error. This means, most frustratingly, I can't inspect the variables at the time of the actual error. Which leads to print-debugging and similar hacks.I recently made a change that went from the above to this:
After this, I get breaks on the actual exception. This makes debugging much better.
I would like to understand why try-catch sometimes doesn't break-on-exception where I'd expect it to. Should we recommend
runZoned
for this reason?Reproduction
I tried to make a minimal reproduction. For a more real-life repro, I can also make a branch of the full project.
example/runner.dart:
lib/try_catch.dart:
test/repro_test.dart:
Instructions
example/runner.dart
as is. This will break on therethrow
, and won't show the actual place where the error occured.const useZoned = true;
and debug-run again. This time, the debugger stops at thethrow
insidefoo()
, and we are able to inspect variables.test/repro_test.dart
. Both tests will pass, despite us rethrowing the error. And the print statements in the catch / onError blocks won't be executed.Screencast
Versions
dart --version
)Dart VM version: 2.7.1 (Thu Jan 23 13:02:26 2020 +0100) on "macos_x64"
MacOS