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:51:09 PDT 2017
On Friday, 12 May 2017 at 08:32:03 UTC, k-five wrote:
> 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
----------------------------------------------------------------
NOT a GOOD solution! Since it accept type and NOT variable:
so:
index = (str.isNumeric) ? to!int(str).ifThrown(0) : 0;
is:
temp.d(11): Error: template std.traits.isNumeric cannot deduce
function from argument types !()(string), candidates are:
More information about the Digitalmars-d-learn
mailing list