BlacKCaT27 / CurrencyEditText

A module designed to encapsulate the use of an Android EditText field for gathering currency information from a user. Supports all ISO-3166 compliant locales/currencies.
Apache License 2.0
339 stars 79 forks source link

NumberFormatException for number greater than Long max value #43

Closed benwicks closed 6 years ago

benwicks commented 6 years ago

java.lang.NumberFormatException: For input string: "10000000000000000000"
    at java.lang.Long.parseLong(Long.java:593)
    at java.lang.Long.valueOf(Long.java:804)
    at com.blackcat.currencyedittext.CurrencyTextWatcher.afterTextChanged(CurrencyTextWatcher.java:49)```
BlacKCaT27 commented 6 years ago

Is there something specific you'd like to see otherwise?

I could wrap it in a library-specific exception, but all that would do is hide/wrap the actual error. I don't plan on supporting something akin to BigInt or anything like that. If you're working with values outside the range of Long.MaxValue, you may have to do some mishmashing of the number yourself to get it to place nicely with the formatter.

On Mon, Nov 27, 2017 at 1:35 PM, Benjamin Wicks notifications@github.com wrote:

java.lang.NumberFormatException: For input string: "10000000000000000000" at java.lang.Long.parseLong(Long.java:593) at java.lang.Long.valueOf(Long.java:804) at com.blackcat.currencyedittext.CurrencyTextWatcher.afterTextChanged(CurrencyTextWatcher.java:49)```

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/BlacKCaT27/CurrencyEditText/issues/43, or mute the thread https://github.com/notifications/unsubscribe-auth/AE_54R43HqmFPvy_keGLgVl1qg8npDFkks5s6wEIgaJpZM4QsF2A .

benwicks commented 6 years ago

What do you think about just catching the exception and ignoring any input that fails the Long.valueOf call?

BlacKCaT27 commented 6 years ago

Having spent the last two weeks at work stuck in javascript hell, I think that silently failing is the bane of all development and anything that fails should fail as loud and as fast as possible. I'm fine with an end-user seeing the occasional error/crash if it means developers are far more likely to see bugs before launching to begin with.

On Mon, Nov 27, 2017 at 3:07 PM, Benjamin Wicks notifications@github.com wrote:

What do you think about just catching the exception and ignoring any input that fails the Long.valueOf call?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/BlacKCaT27/CurrencyEditText/issues/43#issuecomment-347310948, or mute the thread https://github.com/notifications/unsubscribe-auth/AE_54QCznh2hFhQXnpfduOjSZCdxK5Ooks5s6xZ-gaJpZM4QsF2A .

benwicks commented 6 years ago

👍 That makes sense. Thanks for the quick responses!