Skip to content

Provide better tools to detect Errors at runtime #34060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vsmenon opened this issue Aug 1, 2018 · 5 comments
Open

Provide better tools to detect Errors at runtime #34060

vsmenon opened this issue Aug 1, 2018 · 5 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. web-dev-compiler

Comments

@vsmenon
Copy link
Member

vsmenon commented Aug 1, 2018

In general, Error objects aren't treated any differently from Exception objects - developers typically write code that can catch either:

try {
  String s = null;
  s.length;
} catch(e) {
  print(e);
}

Given that our compilers can (under certain flags) assume that Error would not be thrown (see #34044), we should provide better support in our to detect when they occur at runtime during development and testing.

E.g., DDC might provide (or default to) a mode where Error objects cannot be caught (accommodating for frameworks). DDT might provide a 'Pause on Error' option.

@jmesserly @alan-knight @sigmundch

@vsmenon
Copy link
Member Author

vsmenon commented Aug 1, 2018

This actually lines up well with our existing documentation on Error:

https://api.dartlang.org/dev/2.0.0-dev.69.5/dart-core/Error-class.html

Specifically:

These are not errors that a caller should expect or catch - if they occur, the program is erroneous, and terminating the program may be the safest response.

@alan-knight
Copy link
Contributor

For DDT we already pause on Errors, e.g. RangeError. Are we talking about a change to errors where they're not throwing? It would be pretty easy to have DDC compile errors to include a "debugger" statement, possibly conditional.

@vsmenon
Copy link
Member Author

vsmenon commented Aug 1, 2018

I meant differentiating between pausing on a Dart Error vs pausing on anything else (e.g., Exception).

@leafpetersen
Copy link
Member

I wonder if having a debug mode flag to implicitly treat } catch(e) { as } on Exception catch(e) { might be useful? That would mean that unless you are explicitly opting in to catching Error in some way, you won't accidentally swallow Error exceptions.

@vsmenon
Copy link
Member Author

vsmenon commented Aug 2, 2018

Yes, I think we want something like that - although perhaps catching everything except errors (e.g., plain Objects):

catch(e) {
  if (e is Error) rethrow;
  ...
}

@vsmenon vsmenon added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Jul 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. web-dev-compiler
Projects
None yet
Development

No branches or pull requests

3 participants