View source code
Display the source code in std/typecons.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aBugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinglocal clone.

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.

class NotImplementedError
  : Error;

The name came from Class::WhiteHole Perl module by Michael G Schwern.

Constructors

NameDescription
this (method)

Fields

NameTypeDescription
bypassedException ThrowableThe first Exception which was bypassed when this Error was thrown, or null if no Exceptions were pending.
file stringThe file name of the D source code corresponding with where the error was thrown from.
info object.Throwable.TraceInfoThe 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.Throwable.TraceInfo)If set, this is used to deallocate the TraceInfo on destruction.
line ulongThe line number of the D source code corresponding with where the error was thrown from.
msg stringA message describing the error.

Properties

NameTypeDescription
next[get] inout(Throwable)
next[set] ThrowableReplace next in chain with tail. Use chainTogether instead if at all possible.

Methods

NameDescription
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.toString 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

NameDescription
Base A non-final class for WhiteHole to inherit from.

See Also

AutoImplement, generateAssertTrap

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`, &hellip;: 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.writeln( ~ 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

License

Boost License 1.0.