Closed ericel closed 3 years ago
I would expect the try-catch block to work. What's happening if you do that? Does the app crash?
I would expect the try-catch block to work. What's happening if you do that? Does the app crash?
Yes app crashes
I tried your code, funny thing is it crashing in your print statement (print(e.string);
):
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError:
Class 'SocketException' has no instance getter 'string'.
Receiver: Instance of 'SocketException'
Tried calling: string
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
Replacing that with print(e)
just prints the error and returns null. My complete test example: https://gist.github.com/renefloor/2a1593a2431306093d707cbccacb4e92
I tried your code, funny thing is it crashing in your print statement (
print(e.string);
):[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: Class 'SocketException' has no instance getter 'string'. Receiver: Instance of 'SocketException' Tried calling: string #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
Replacing that with
print(e)
just prints the error and returns null. My complete test example: https://gist.github.com/renefloor/2a1593a2431306093d707cbccacb4e92
That was a typo error when reporting the issue here, it should be a e.toString(). It doesn't really solve this:
That looks like the debugger that stops. The Dart VM debugger has a bug that it doesn't always know that an exception is caught. See this recent comment, but the debate is already quite old: https://github.com/dart-lang/sdk/issues/37953#issuecomment-760256848
Is it correct that your debugger pauses, but your app doesn't crash?
Right! thank you.
💬 Questions and Help
This part of the code throws an error when the file from the web doesn't exist.
It would be nice if a try / catch block can handle the error. What would be a better way to silence this error... I tried
That doesn't seem to handle the error.