DIP33: A standard exception hierarchy
Steven Schveighoffer
schveiguy at yahoo.com
Tue Apr 2 06:44:16 PDT 2013
On Tue, 02 Apr 2013 02:55:43 -0400, Jacob Carlborg <doob at me.com> wrote:
> The obvious solution to that would be to be able to specify multiple
> exception types for a single catch block:
>
> catch (MySpecificException1, MySpecificException2 ex)
> {
> }
Yes, this could help. But it's still not great. One must still store a
"type identifier" in the ex, or have to deal with casting to figure out
what type ex is.
It also promotes creating a new type for every single catchable situation.
Consider that we could create one exception type that contains an 'errno'
member, and if we have the ability to run extra checks for catching you
could do:
catch(ErrnoException ex) if (ex.errno == EBADF || ex.errno == EBADPARAM)
{
...
}
But if we must do it with types, we need:
class ErrnoException(uint e) : Exception
{
enum errno = e;
}
or worse, to make things easier to deal with we have:
class ErrnoException : Exception
{
int errno;
this(int errno) { this.errno = errno; }
}
class ErrnoExceptionT(uint e) : ErrnoException
{
this() { super(e); }
}
which would be easier to deal with, but damn what a waste! Either way,
every time you catch another errno exception, we are talking about
instantiating another type.
I think the solution with a categorical errno exception, with a simple
errno stored as a variable (along with the ability to catch based on it)
is much cleaner IMO, and I wonder if testing members instead of typeids
might be more efficient in the stack unwinding code.
-Steve
More information about the Digitalmars-d
mailing list