The Right Approach to Exceptions
Jonathan M Davis
jmdavisProg at gmx.com
Sun Feb 19 14:54:36 PST 2012
On Sunday, February 19, 2012 11:13:46 Robert Jacques wrote:
> Most of Phobos is an internal library. I think parsing routines are a bad
> counter-example to my point; combined validation and conversion is
> generally part of their mandate and we expect them to fail often. We also
> don't expect the parsing of user input to live deep inside code base; it's
> almost always done as close to the input as possible (i.e. in the input
> text box). All too often you end up with code like: try{ parse(...); }
> catch {...} Also, although less of a problem in D,
It very much depends on the function. In some cases, it makes the most sense
to use assertions. In others, it makes the most sense to use exceptions. You
have to examine it on a case-by-case basis. For instance, most of
std.algorithm asserts on stuff, whereas the unicode stuff generally enforces.
> not ensuring that in
> input string actually is a string was the source of many a C exploits.
That may be, but that really doesn't apply to D aside from how you should be
interacting with C functions that involve char*.
- Jonathna M Davis
More information about the Digitalmars-d
mailing list