DIP76: Autodecode Should Not Throw

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 7 02:04:07 PDT 2015


On 4/7/2015 1:19 AM, Dicebot wrote:
> I have doubts about it similar to Vladimir. Main problem is that I have no idea
> what actually happens if replacement characters appear in some unicode text my
> program processes.

It's much like floating point NaN values, which are 'sticky'.

> So far I have that calming feeling that if something goes
> wrong in this regard, exception will slap me right into my face.

With UTF strings, if you care about invalid UTF (a surprisingly large amount of 
operations done on strings simply don't care about invalid UTF) the validation 
can be done as a separate step. Then, the program logic is divided into 
operating on "validated" and "unvalidated" data.

> Also it is worrying to see so much effort put into `nothrow` in language which
> endorses exceptions as its main error reporting mechanism.

There is definitely a tug of war going on there. Exceptions are great, except 
they aren't free.

What I've tried to do is design things so that erroneous input is not possible - 
that all possible input has straightforward output. In other words, try to 
define the problem out of existence. Then there are no errors.


More information about the Digitalmars-d mailing list