More exception classes into Phobos?

Георгий via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 28 01:29:44 PDT 2017


On Thursday, 23 March 2017 at 16:44:51 UTC, Jonathan M Davis 
wrote:
>
> Classes should not be implementing interfaces only to throw 
> exceptions when they don't really want to be implementing some 
> of the functionality of that interface. That's just plain bad 
> design.
>

There are the cases, when NotImplementedException is the good 
choice, except for the pure Exception.
Currently, I am making the inter-server communication code. Now 
we have the situation, where there are many servers with 
different settings. So, in the master app I create 2 enums, say, 
MySettingsVariant, SlaveSettingsVariant. Then I'll rewrite the 
small piece of communication code, depends on their combinations. 
And the code will look like:

if (my == X && its == Y) {
} else if (my == Z && its == Y) {
} else {
     throw new NotImplementedException();
}

Well, when somebody will add a value in one of these enums and 
will forget to write something for the new combinations, he/she 
will get the meaningful stacktrace in the log. Well, I agree, 
it's very close to just throw Exception. The only difference in 
the name. But when I talked about NIE, I meant such cases in the 
first place (not the partial interface implementations as in some 
Java collections).

I just say. I don't persuade to add it to Phobos.


More information about the Digitalmars-d mailing list