More exception classes into Phobos?

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 28 11:07:01 PDT 2017


On 2017-03-28 11:25, Walter Bright wrote:

> If you received an IOException instead, you're no better off.

No, I agree. But I have not argued for or against a standardize 
exception hierarchy. I've argued that we need more specific error types 
(either as a hierarchy or flat structure).

> As Andrei observed, it is the message that's the problem, not the exception type.

It's an issue with both. It's an issue with the exception type because I 
cannot really handle the error in any sensible way. In my opinion the 
error message is more of a debug aid.

> In general, I think a lot of the issues you brought up are inadequate
> messages, or trying to solve the problem at the wrong level of the
> function call hierarchy (i.e. too far up).

void main()
{
     import std.stdio;

     try
         copy("/tmp/foo.txt", "/tmp/bar/foo.txt");
     catch (FileException e)
     {
         // handle permission error?
     }
}

How should I handle a permission error in the above example? It's not 
possible to do so without parsing the error message. This is catching 
the exception as close as possible to the source (without modifying Phobos).

> In any case, trying to get good messages to the user is a never ending
> problem. No solution will be universal. It's actually a lot like writing
> portable code. People who have never ported code tend to make all the
> wrong choices in where to make things portable (see windows.h for 16 bit
> Windows). Crafting an exception hierarchy with no experience with nor
> clear idea of the problem one is trying to solve just creates a complex,
> useless mess. I fear that's the path we've gone down.

Again, I have not argued for or against an exception hierarchy.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list