Google's Go & Exceptions

Ary Borenszweig ary at esperanto.org.ar
Wed Jan 27 04:42:52 PST 2010


Nick Sabalausky wrote:
> "Walter Bright" <newshound1 at digitalmars.com> wrote in message 
> news:hjo5t3$2dqq$1 at digitalmars.com...
>> Ary Borenszweig wrote:
>>> auto x = new BigInt(someString);
>>>
>>> How do you implement BigInt's constructor without being able to throw an 
>>> exception?
>>
>> I presume you mean how can it work without allocating memory. In D, a 
>> memory allocation failure is generally not a recoverable exception, it's a 
>> fatal exception.
>>
>> A better example would be one that attempted to open a file in the 
>> constructor.
> 
> I think he meant that passing it something like "Hello, Fred." should be 
> disallowed. 

Yes, that. I don't see another way rather than throwing an exception. Or 
maybe just do like ruby, when you do "hello".to_i it gives you zero but 
then you have to check it later.

I don't like factory methods like BigInt.fromString. If I want to create 
a BigInt from a string I should use the constructor, why not?



More information about the Digitalmars-d mailing list