Skip to content
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

Int64#parse* method docs should declare what exceptions they throw #32383

Closed
trinarytree opened this issue Mar 2, 2018 · 4 comments
Closed

Comments

@trinarytree
Copy link

Int64#parse{Hex, Int, Radix} apparently throw FormatException.
this should be declared in their docs so that callers can narrow a surrounding try-catch
to just the correct exception type.

@rakudrama
Copy link
Member

It would be easier to use and more efficient to provide tryParse methods that return null if the input is malformed.

@vsmenon
Copy link
Member

vsmenon commented Mar 2, 2018

This is from package:fixnum? @trinarytree - can you please file there:

https://github.com/dart-lang/fixnum

?

@trinarytree
Copy link
Author

i only intended this issue to be about fixing the docs, so the following will be slightly off topic:

if one were to redesign the interface, it should probably work like int.parse or double.parse.
unfortunately, those don't work exactly like each other.

  • int.parse has has an optional named param named onError.
  • double.parse has an optional positional param named onError.
    a named param is probably better because these will often be used with anonymous function expressions. e.g.
double.parse('e10', (_) => 1.23)

is less readable than

int.parse('e10', onError: (_) => 123)

if redesigning the interface is seriously on the table, let's spin off a separate issue.

@trinarytree
Copy link
Author

i moved this issue to dart-lang/core#153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants