[eol][evl]Handling exception in casting types [message #763322] |
Fri, 09 December 2011 10:09  |
Eclipse User |
|
|
|
hi everybody
I have a class with a <<value>> string field. The purpose of this field is to receive any input data (integers, booleans, reals and strings) and then casting to the desiredtype (like Integer, Boolean, Real ...).
The casting (conversion) of this <<value>> field is happening in a .evl file.
In EVL i'm trying to know if the content of <<value>> field is consistent with the choosen type.
for instance
<<value>> field | choosen type
true boolean It's ok!
Today Integer It isn't ok because ''today'' is not a integer
To do that, I've tried this (to convert from String to Integer)
check: self.valor.asInteger().isKindOf(Integer)
when <<value>> is an Integer, this works well but it isn't this piece of code raises an exception and I couldn't find a way to handling exception in eol or evl.
I'd appreciate any help.
Thanks in advance!
|
|
|
Re: [eol][evl]Handling exception in casting types [message #763419 is a reply to message #763322] |
Fri, 09 December 2011 12:11   |
Eclipse User |
|
|
|
Hi Paulo,
The code you have written would not check the validity of the string. If
asInteger() is successful it will, per definition, return an integer. So
calling isKindOf (Integer) on it is redundant!
You will probably need to build a helper class of your own to provide
appropriate testing and conversion methods. Check out the 'tools'
concept in the Epsilon book.
Cheers,
Steffen
On 09/12/2011 15:09, Paulo Alexandre wrote:
> hi everybody
>
> I have a class with a <<value>> string field. The purpose of this
> field is to receive any input data (integers, booleans, reals and
> strings) and then casting to the desiredtype (like Integer, Boolean,
> Real ...).
>
> The casting (conversion) of this <<value>> field is happening in a
> .evl file.
>
> In EVL i'm trying to know if the content of <<value>> field is
> consistent with the choosen type.
>
> for instance
> <<value>> field | choosen type true boolean
> It's ok!
> Today Integer It isn't ok because ''today'' is
> not a integer
>
> To do that, I've tried this (to convert from String to Integer)
>
> check: self.valor.asInteger().isKindOf(Integer)
>
> when <<value>> is an Integer, this works well but it isn't this piece
> of code raises an exception and I couldn't find a way to handling
> exception in eol or evl.
>
> I'd appreciate any help.
>
> Thanks in advance!
>
>
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04543 seconds