Class std.typecons.NotImplementedError
WhiteHole!Base
is a subclass of Base
which automatically implements
all abstract member functions as functions that always fail. These functions
simply throw an Error
and never return. Whitehole
is useful for
trapping the use of class member functions that haven't been implemented.
The name came from Class::WhiteHole Perl module by Michael G Schwern.
Constructors
Name | Description |
---|---|
this
(method)
|
Fields
Name | Type | Description |
---|---|---|
bypassedException
|
Throwable | The first Exception which was bypassed when this Error was thrown,
or null if no Exception s were pending.
|
file
|
string | The file name of the D source code corresponding with where the error was thrown from. |
info
|
object | The stack trace of where the error happened. This is an opaque object
that can either be converted to string , or iterated over with foreach to extract the items in the stack trace (as strings).
|
infoDeallocator
|
nothrow void function(object | If set, this is used to deallocate the TraceInfo on destruction. |
line
|
ulong | The line number of the D source code corresponding with where the error was thrown from. |
msg
|
string | A message describing the error. |
Properties
Name | Type | Description |
---|---|---|
next [get]
|
inout(Throwable) | |
next [set]
|
Throwable | Replace next in chain with tail .
Use chainTogether instead if at all possible.
|
Methods
Name | Description |
---|---|
chainTogether
(e1, e2)
|
Append e2 to chain of exceptions that starts with e1 .
|
factory
(classname)
|
Create instance of class specified by the fully qualified name classname. The class must either have no constructors or have a default constructor. |
message
()
|
Get the message describing the error. |
opApply
(dg)
|
Loop over the chain of Throwables. |
opCmp
(o)
|
Compare with another Object obj. |
opEquals
(o)
|
Test whether this is equal to o .
The default implementation only compares by identity (using the is operator).
Generally, overrides and overloads for opEquals should attempt to compare objects by their contents.
A class will most likely want to add an overload that takes your specific type as the argument
and does the content comparison. Then you can override this and forward it to your specific
typed overload with a cast. Remember to check for null on the typed overload.
|
refcount
()
|
|
toHash
()
|
Compute hash function for Object. |
toString
()
|
Overrides Object and returns the error message.
Internally this forwards to the toString overload that
takes a sink delegate.
|
toString
(sink)
|
The Throwable hierarchy uses a toString overload that takes a
sink delegate to avoid GC allocations, which cannot be
performed in certain error situations. Override this toString method to customize the error message.
|
Parameters
Name | Description |
---|---|
Base | A non-final class for WhiteHole to inherit from. |
See Also
Example
import std .exception : assertThrown;
static class C
{
abstract void notYetImplemented();
}
auto c = new WhiteHole!C;
assertThrown!NotImplementedError(c .notYetImplemented()); // throws an Error
Example
import std .exception : assertThrown;
// nothrow
{
interface I_1
{
void foo();
void bar() nothrow;
}
auto o = new WhiteHole!I_1;
assertThrown!NotImplementedError(o .foo());
assertThrown!NotImplementedError(o .bar());
}
// doc example
{
static class C
{
abstract void notYetImplemented();
}
auto c = new WhiteHole!C;
try
{
c .notYetImplemented();
assert(0);
}
catch (Error e) {}
}
}
/**
`AutoImplement` automatically implements (by default) all abstract member
functions in the class or interface `Base` in specified way.
The second version of `AutoImplement` automatically implements
`Interface`, while deriving from `BaseClass`.
Params:
how = template which specifies _how functions will be implemented/overridden.
Two arguments are passed to `how`: the type `Base` and an alias
to an implemented function. Then `how` must return an implemented
function body as a string.
The generated function body can use these keywords:
<ul> <li>`a0`, `a1`, …: arguments passed to the function;</li>
<li>`args`: a tuple of the arguments;</li>
<li>`self`: an alias to the function itself;</li>
<li>`parent`: an alias to the overridden function (if any).</li>
</ul>
You may want to use templated property functions (instead of Implicit
Template Properties) to generate complex functions:
// Prints log messages for each call to overridden functions. string generateLogger(C, alias fun)() @property { import std.traits; enum qname = C.stringof ~ "." ~ _traits(identifier, fun); string stmt;
stmt ~= q{ struct Importer { import std.stdio; } };
stmt ~= Importer
~ qname ~ (", args, ")
;
static if (!_traits(isAbstractFunction, fun))
{
static if (is(ReturnType!fun == void))
stmt ~= q{ parent(args); };
else
stmt ~= q{
auto r = parent(args);
Importer.writeln("--> ", r);
return r;
};
}
return stmt;
Authors
Andrei Alexandrescu, Bartosz Milewski, Don Clugston, Shin Fujishiro, Kenji Hara