How to avoid throwing an exceptions for a built-in function?
k-five via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed May 10 06:27:17 PDT 2017
On Wednesday, 10 May 2017 at 13:12:46 UTC, Ivan Kazmenko wrote:
> On Wednesday, 10 May 2017 at 12:40:41 UTC, k-five wrote:
----------------------------------------------------------
>
> I assume that an empty string is a valid input then.
> The question is, what value do you want `index` to have when
> the string is empty?
> Maybe the old value, or some constant?
> In any case, to better express your intent, you may write
> something like:
>
> if (user_apply[4] != "")
> {
> index = to !(int) (user_apply[4]);
> }
> else
> {
> index = ...; // specify whatever your intent is
> }
>
> This way, the code is self-documenting, and the program still
> throws when `user_apply[4]` is neither empty nor an integer,
> which may be the right thing to do in the long run.
>
> Ivan Kazmenko.
----------------------------------------------------------
Thanks, but I know about what are you saying. The user_apply[4]
has so many possibilities and I cannot use if-else
More information about the Digitalmars-d-learn
mailing list