diff --git a/std/concurrency.d b/std/concurrency.d index e15e3e129..bc31c7137 100644 --- a/std/concurrency.d +++ b/std/concurrency.d @@ -299,10 +299,7 @@ class MailboxFull : Exception */ class TidMissingException : Exception { - this(string msg, string file = __FILE__, size_t line = __LINE__) - { - super(msg, file, line); - } + mixin basicExceptionCtors; } @@ -1695,8 +1692,7 @@ void yield(T)(ref T value) cur.m_value = &value; return Fiber.yield(); } - throw new Exception("yield(T) called with no active generator for the supplied type", - __FILE__, __LINE__); + throw new Exception("yield(T) called with no active generator for the supplied type"); } diff --git a/std/csv.d b/std/csv.d index ff2bc4b3a..8052e5f50 100644 --- a/std/csv.d +++ b/std/csv.d @@ -94,6 +94,7 @@ module std.csv; import std.conv; import std.range.primitives; import std.traits; +import std.exception; // basicExceptionCtors /** * Exception containing the row and column for when an exception was thrown. @@ -111,20 +112,22 @@ class CSVException : Exception /// size_t row, col; + // FIXME: Use std.exception.basicExceptionCtors here once bug #11500 is fixed + this(string msg, string file = __FILE__, size_t line = __LINE__, - Throwable next = null) @safe pure + Throwable next = null) @nogc @safe pure nothrow { super(msg, file, line, next); } this(string msg, Throwable next, string file = __FILE__, - size_t line = __LINE__) @safe pure + size_t line = __LINE__) @nogc @safe pure nothrow { super(msg, file, line, next); } this(string msg, size_t row, size_t col, Throwable next = null, - string file = __FILE__, size_t line = __LINE__) @safe pure + string file = __FILE__, size_t line = __LINE__) @nogc @safe pure nothrow { super(msg, next, file, line); this.row = row; @@ -171,17 +174,7 @@ class IncompleteCellException : CSVException /// already been fed to the output range. dstring partialData; - this(string msg, string file = __FILE__, size_t line = __LINE__, - Throwable next = null) @safe pure - { - super(msg, file, line); - } - - this(string msg, Throwable next, string file = __FILE__, size_t line = - __LINE__) @safe pure - { - super(msg, next, file, line); - } + mixin basicExceptionCtors; } @safe pure unittest @@ -213,17 +206,7 @@ class IncompleteCellException : CSVException */ class HeaderMismatchException : CSVException { - this(string msg, string file = __FILE__, size_t line = __LINE__, - Throwable next = null) @safe pure - { - super(msg, file, line); - } - - this(string msg, Throwable next, string file = __FILE__, - size_t line = __LINE__) @safe pure - { - super(msg, next, file, line); - } + mixin basicExceptionCtors; } @safe pure unittest diff --git a/std/getopt.d b/std/getopt.d index e6cf7ded6..6358fd2dc 100644 --- a/std/getopt.d +++ b/std/getopt.d @@ -33,6 +33,7 @@ Distributed under the Boost Software License, Version 1.0. module std.getopt; import std.traits; +import std.exception; // basicExceptionCtors /** Thrown on one of the following conditions: @@ -45,18 +46,7 @@ $(UL */ class GetOptException : Exception { - @safe pure nothrow - this(string msg, string file = __FILE__, - size_t line = __LINE__) - { - super(msg, file, line); - } - @safe pure nothrow - this(string msg, Exception next, string file = __FILE__, - size_t line = __LINE__) - { - super(msg, file, line, next); - } + mixin basicExceptionCtors; } static assert(is(typeof(new GetOptException("message")))); diff --git a/std/process.d b/std/process.d index 7c43f1f43..20d3e4b4c 100644 --- a/std/process.d +++ b/std/process.d @@ -2186,15 +2186,10 @@ unittest } } - /// An exception that signals a problem with starting or waiting for a process. class ProcessException : Exception { - // Standard constructor. - this(string msg, string file = __FILE__, size_t line = __LINE__) - { - super(msg, file, line); - } + mixin basicExceptionCtors; // Creates a new ProcessException based on errno. static ProcessException newFromErrno(string customMsg = null, diff --git a/std/regex/internal/ir.d b/std/regex/internal/ir.d index 04cec1f70..54c112cde 100644 --- a/std/regex/internal/ir.d +++ b/std/regex/internal/ir.d @@ -741,9 +741,5 @@ int quickTestFwd(RegEx)(uint pc, dchar front, const ref RegEx re) ///Exception object thrown in case of errors during regex compilation. public class RegexException : Exception { - /// - @trusted this(string msg, string file = __FILE__, size_t line = __LINE__) - {//@@@BUG@@@ Exception constructor is not @safe - super(msg, file, line); - } + mixin basicExceptionCtors; } diff --git a/std/socket.d b/std/socket.d index 63c65d315..94f5e321d 100644 --- a/std/socket.d +++ b/std/socket.d @@ -50,7 +50,7 @@ import core.stdc.stdint, core.stdc.string, std.string, core.stdc.stdlib, std.con import core.stdc.config; import core.time : dur, Duration; -import std.exception : assumeUnique, enforce, collectException; +import std.exception; import std.internal.cstring; @@ -145,17 +145,7 @@ version(unittest) /// Base exception thrown by $(D std.socket). class SocketException: Exception { - /// - this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) pure nothrow - { - super(msg, file, line, next); - } - - /// - this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) pure nothrow - { - super(msg, next, file, line); - } + mixin basicExceptionCtors; } @@ -279,34 +269,14 @@ class SocketOSException: SocketException /// Socket exceptions representing invalid parameters specified by user code. class SocketParameterException: SocketException { - /// - this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) pure nothrow - { - super(msg, file, line, next); - } - - /// - this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) pure nothrow - { - super(msg, next, file, line); - } + mixin basicExceptionCtors; } /// Socket exceptions representing attempts to use network capabilities not /// available on the current system. class SocketFeatureException: SocketException { - /// - this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) pure nothrow - { - super(msg, file, line, next); - } - - /// - this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) pure nothrow - { - super(msg, next, file, line); - } + mixin basicExceptionCtors; } @@ -625,30 +595,39 @@ unittest } -/** - * Class for exceptions thrown from an $(D InternetHost). - */ -class HostException: SocketOSException +private mixin template socketOSExceptionCtors() { /// - this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null, int err = _lasterr()) + this(string msg, string file = __FILE__, size_t line = __LINE__, + Throwable next = null, int err = _lasterr()) { super(msg, file, line, next, err); } /// - this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__, int err = _lasterr()) + this(string msg, Throwable next, string file = __FILE__, + size_t line = __LINE__, int err = _lasterr()) { super(msg, next, file, line, err); } /// - this(string msg, int err, string file = __FILE__, size_t line = __LINE__, Throwable next = null) + this(string msg, int err, string file = __FILE__, size_t line = __LINE__, + Throwable next = null) { super(msg, next, file, line, err); } } + +/** + * Class for exceptions thrown from an $(D InternetHost). + */ +class HostException: SocketOSException +{ + mixin socketOSExceptionCtors; +} + /** * $(D InternetHost) is a class for resolving IPv4 addresses. * @@ -1251,23 +1230,7 @@ unittest */ class AddressException: SocketOSException { - /// - this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null, int err = _lasterr()) - { - super(msg, file, line, next, err); - } - - /// - this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__, int err = _lasterr()) - { - super(msg, next, file, line, err); - } - - /// - this(string msg, int err, string file = __FILE__, size_t line = __LINE__, Throwable next = null) - { - super(msg, next, file, line, err); - } + mixin socketOSExceptionCtors; } @@ -2080,23 +2043,7 @@ static if (is(sockaddr_un)) */ class SocketAcceptException: SocketOSException { - /// - this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null, int err = _lasterr()) - { - super(msg, file, line, next, err); - } - - /// - this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__, int err = _lasterr()) - { - super(msg, next, file, line, err); - } - - /// - this(string msg, int err, string file = __FILE__, size_t line = __LINE__, Throwable next = null) - { - super(msg, next, file, line, err); - } + mixin socketOSExceptionCtors; } /// How a socket is shutdown: diff --git a/std/uri.d b/std/uri.d index b520c3316..658cc7e48 100644 --- a/std/uri.d +++ b/std/uri.d @@ -36,20 +36,14 @@ private import core.stdc.stdlib; private import std.utf; private import std.traits : isSomeChar; import core.exception : OutOfMemoryError; -import std.exception : assumeUnique; +import std.exception; /** This Exception is thrown if something goes wrong when encoding or decoding a URI. */ class URIException : Exception { - import std.array : empty; - @safe pure nothrow this(string msg, string file = __FILE__, - size_t line = __LINE__, Throwable next = null) - { - super("URI Exception" ~ (!msg.empty ? ": " ~ msg : ""), file, line, - next); - } + mixin basicExceptionCtors; } private enum diff --git a/std/utf.d b/std/utf.d index 895ba72dd..ac856b026 100644 --- a/std/utf.d +++ b/std/utf.d @@ -20,10 +20,11 @@ +/ module std.utf; -import std.meta; // AliasSeq +import std.meta; // AliasSeq import std.range.primitives; -import std.traits; // isSomeChar, isSomeString -import std.typecons : Flag; +import std.traits; // isSomeChar, isSomeString +import std.typecons; // Flag +import std.exception; // basicExceptionCtors //debug=utf; // uncomment to turn on debugging printf's @@ -51,14 +52,16 @@ class UTFException : Exception return this; } - @safe pure nothrow - this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) + // FIXME: Use std.exception.basicExceptionCtors here once bug #11500 is fixed + + this(string msg, string file = __FILE__, size_t line = __LINE__, + Throwable next = null) @nogc @safe pure nothrow { super(msg, file, line, next); } - @safe pure - this(string msg, size_t index, string file = __FILE__, size_t line = __LINE__, Throwable next = null) + this(string msg, size_t index, string file = __FILE__, + size_t line = __LINE__, Throwable next = null) @safe pure nothrow { UnsignedStringBuf buf = void; msg ~= " (at index " ~ unsignedToTempString(index, buf, 10) ~ ")"; @@ -306,7 +309,7 @@ unittest { import std.conv : to; import std.exception; - import std. string : format; + import std.string : format; import core.exception : AssertError; static void test(string s, dchar c, size_t i = 0, size_t line = __LINE__) { @@ -414,7 +417,7 @@ unittest { import std.conv : to; import std.exception; - import std. string : format; + import std.string : format; import core.exception : AssertError; static void test(wstring s, dchar c, size_t i = 0, size_t line = __LINE__) { @@ -493,7 +496,7 @@ unittest { import std.conv : to; import std.exception; - import std. string : format; + import std.string : format; import core.exception : AssertError; static void test(dstring s, dchar c, size_t i = 0, size_t line = __LINE__) { @@ -639,7 +642,7 @@ unittest { import std.conv : to; import std.exception; - import std. string : format; + import std.string : format; import core.exception : AssertError; static void test(string s, dchar c, size_t i = size_t.max, size_t line = __LINE__) { @@ -736,7 +739,7 @@ unittest { import std.conv : to; import std.exception; - import std. string : format; + import std.string : format; import core.exception : AssertError; static void test(wstring s, dchar c, size_t i = size_t.max, size_t line = __LINE__) { @@ -821,7 +824,7 @@ unittest { import std.conv : to; import std.exception; - import std. string : format; + import std.string : format; import core.exception : AssertError; static void test(dstring s, dchar c, size_t i = size_t.max, size_t line = __LINE__) { @@ -1579,7 +1582,7 @@ version(unittest) private void testDecode(R)(R range, size_t line = __LINE__) { import std.exception; - import std. string : format; + import std.string : format; import core.exception : AssertError; static if (hasLength!R) @@ -1608,7 +1611,7 @@ version(unittest) private void testDecodeFront(R)(ref R range, size_t line = __LINE__) { import std.exception; - import std. string : format; + import std.string : format; import core.exception : AssertError; static if (hasLength!R) @@ -1640,7 +1643,7 @@ version(unittest) private void testBothDecode(R)(R range, version(unittest) private void testBadDecode(R)(R range, size_t index, size_t line = __LINE__) { import std.exception; - import std. string : format; + import std.string : format; import core.exception : AssertError; immutable initialIndex = index; @@ -2815,7 +2818,7 @@ private P toUTFzImpl(P, S)(S str) @safe pure { import std.conv : to; import std.exception; - import std. string : format; + import std.string : format; import core.exception : AssertError; import std.algorithm;