String.to_integer/1 why no exclamation mark?

Surely this has been asked and explained before, but for some reason I couldn’t find it.

String.to_integer/1 docs say:

string must be the string representation of an integer. Otherwise, an ArgumentError will be raised.

If an exception is a possibility and there is a convention of marking such functions with a trailing exclamation mark in the name, why doesn’t this function have it?

Thanks!

1 Like

Because there is no non-raising analog function with the same name. If you take a closer look, all bang functions have their analogs without bangs.

FYI, If you want to handle parsing error, use Integer.parse

That’s not quite correct. In the same conventions linked above we read:

There are also some non-paired functions, with no non-bang variant. The bang still signifies that it will raise an exception on failure. Example: Protocol.assert_protocol!/1.

To be clear, my question is nomenclatural, I’m not looking for workarounds.

Hmm, you’re right. Well, it is a good question for someone from Elixir core team