How to avoid throwing an exceptions for a built-in function?
k-five via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri May 12 01:32:03 PDT 2017
On Thursday, 11 May 2017 at 19:59:55 UTC, Jordan Wilson wrote:
> On Thursday, 11 May 2017 at 18:07:47 UTC, H. S. Teoh wrote:
>> On Thu, May 11, 2017 at 05:55:03PM +0000, k-five via
>> Digitalmars-d-learn wrote:
>>> On Thursday, 11 May 2017 at 17:18:37 UTC, crimaniak wrote:
>>> > On Wednesday, 10 May 2017 at 12:40:41 UTC, k-five wrote:
>>> ---------------------------------------------------------
>
> This reason is why I sometimes use isNumeric if I have heaps of
> strings I need to convert, to reduce exceptions. So something
> like:
> int index = (str.isNumeric) ? to!int(str).ifThrown(0) : 0;
>
> Jordan
--------------------------------------------------------------
Interesting! I was worried about performance and for that I did
not want to use try-catch.
So (isNumberic) is a good solution.
http://dlang.org/phobos/std_traits.html#isNumeric
More information about the Digitalmars-d-learn
mailing list