How to avoid throwing an exceptions for a built-in function?
k-five via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 11 09:07:22 PDT 2017
On Wednesday, 10 May 2017 at 21:19:21 UTC, Stanislav Blinov wrote:
> On Wednesday, 10 May 2017 at 15:35:24 UTC, k-five wrote:
>> On Wednesday, 10 May 2017 at 14:27:46 UTC, Stanislav Blinov
---------------------------------------------------------------
> I don't understand. If you don't want to take care of
> exceptions, then you just don't do anything, simply call
> to!int(str).
Well I did that, but when the string is a valid type like: "10"
there is no problems. But when the string is not valid, like:
"abc", then to! function throws an exception.
Why I do not want to take care of that? Because I just need the
value, if the string is valid, otherwise no matter what the value
of string is.
First I just wrote:
index = to!int( user_apply[ 4 ] );
And this code is a part of a command-line program and the user
may enter anything. So, for a valid string:
./program '10' // okey
but for:
./program 'non-numerical' // throws an exception an 10 lines of
error appear on the screen( console )
I just want to silent this exception. Of course it is useful for
handling when someone wants to. But in my code I no need to
handle it. So I want to silent that, without using try{}catch(){}
block. I just wondered about try-catch and I want to know may
there would be a better way instead of a dummy try-catch block.
Thanks for replying and mentioning. And I am sorry, since I an
new in English Writing, if you got confuse.
More information about the Digitalmars-d-learn
mailing list