Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsOperation, asInteger() and EOLInteger constructor
https://www.eclipse.org/forums/index.php/mv/msg/180109/571501/#msg_571501
Just a quick note really.
The other day I was applying asInteger() to certain Strings (which would
usually be number characters). In the Epsilon book, I saw that an error
would be raised if the Strings weren't of an acceptable form (pg. 33). But
I found this not to be the case.
Looking in the EOLInteger constructor (which I believe asInteger() uses),
I see that if the String isn't of a valid form, the EOLInteger object is
set to 0. And in practice, this was the behaviour I was experiencing,
i.e., I didn't get an error even when the String wasn't a number, e.g.,
'Tilly the cat'.
Given this behaviour, I use the following rather pointless looking
operation to determine if a String can be parsed as an integer:
Would it make sense to add an operation to EOLString, which could check if
it could indeed be parsed as an integer? I guess I only suggest this
because if an error was raised after trying to parse an unacceptable
String as an integer, I wouldn't know how to handle the error in Epsilon,
e.g., if the error was an exception thrown by the underpinning Java.
Moreover, it would allow you to check for such cases at runtime without
your application stopping.