Benchmark of try/catch

Denis Koroskin 2korden at gmail.com
Mon Mar 23 14:37:14 PDT 2009


On Mon, 23 Mar 2009 16:32:03 +0300, Daniel Keep <daniel.keep.lists at gmail.com> wrote:

>
>
> bearophile wrote:
>> grauzone:
>>
>>> From your site:<
>>
>> I don't own LiveJournal :-) That's just my blog, my site is elsewhere.
>>
>>
>>> Using exceptions in a string->int conversion routine is really  
>>> horrible and incredibly stupid.<
>>
>> I agree that it's not nice looking, but in Python that's the standard  
>> idiom.
>> In D I do the same thing when I want to know if a string contains an  
>> integer or float, with toInt/toFloat, how can I do it with no  
>> exceptions?
>>
>> Python3 also removes the find() method of strings, and leaves only the  
>> index() method, that is like find(), but raise ValueError when the  
>> substring is not found. So you are forced to use exceptions here too.
>>
>> So far in D I have used exceptions to control flow only once, in this  
>> library module (original code idea by Witold Baryluk, modified):
>> http://www.fantascienza.net/leonardo/so/dlibs/generators.html
>>
>> Bye,
>> bearophile
>
> Andrei already solved this problem; I'm just waiting for its
> implementation to be possible in D...
>
> http://www.nwcpp.org/Meetings/2006/05.html
>
> :D
>
>   -- Daniel

Yay, The Power of None! That's what I was referring to when proposed nullable types:

int? value1 = atoi("0");   // 0
int? value2 = atoi("#!$"); // null




More information about the Digitalmars-d mailing list