diff --git a/dyaml/composer.d b/dyaml/composer.d index 1a989fc..2283dc2 100644 --- a/dyaml/composer.d +++ b/dyaml/composer.d @@ -32,12 +32,7 @@ package: */ class ComposerException : MarkedYAMLException { - this(string context, Mark contextMark, string problem, Mark problemMark) - { - super(context, contextMark, problem, problemMark); - } - - this(string problem, Mark problemMark){super(problem, problemMark);} + mixin MarkedExceptionCtors; } ///Composes YAML documents from events provided by a Parser. diff --git a/dyaml/constructor.d b/dyaml/constructor.d index 47c15f4..d8fa438 100644 --- a/dyaml/constructor.d +++ b/dyaml/constructor.d @@ -43,9 +43,10 @@ class ConstructorException : YAMLException * start = Start position of the error context. * end = End position of the error context. */ - this(string msg, Mark start, Mark end) + this(string msg, Mark start, Mark end, string file = __FILE__, int line = __LINE__) { - super(msg ~ "\nstart:" ~ start.toString() ~ "\nend:" ~ end.toString()); + super(msg ~ "\nstart:" ~ start.toString() ~ "\nend:" ~ end.toString(), + file, line); } } diff --git a/dyaml/emitter.d b/dyaml/emitter.d index 8647030..3058e89 100644 --- a/dyaml/emitter.d +++ b/dyaml/emitter.d @@ -37,12 +37,15 @@ import dyaml.util; package: -///Exception thrown at Emitter errors. +/** + * Exception thrown at Emitter errors. + * + * See_Also: + * YAMLException + */ class EmitterException : YAMLException { - public: - ///Construct an EmitterException with specified message. - this(string msg){super(msg);} + mixin ExceptionCtors; } //Stores results of analysis of a scalar, determining e.g. what scalar style to use. diff --git a/dyaml/exception.d b/dyaml/exception.d index ec8c1a1..bdd6a8f 100644 --- a/dyaml/exception.d +++ b/dyaml/exception.d @@ -17,8 +17,11 @@ import std.string; class YAMLException : Exception { public: - ///Construct a YAMLException with specified message. - this(string msg){super(msg);} + ///Construct a YAMLException with specified message, and position where it was thrown. + this(string msg, string file = __FILE__, int line = __LINE__) + { + super(msg, file, line); + } package: //Set name of the file that was being processed when this exception was thrown. @@ -59,17 +62,45 @@ package: abstract class MarkedYAMLException : YAMLException { //Construct a MarkedYAMLException with specified context and problem. - this(string context, Mark contextMark, string problem, Mark problemMark) + this(string context, Mark contextMark, string problem, Mark problemMark, + string file = __FILE__, int line = __LINE__) { string msg = context ~ '\n'; if(contextMark != problemMark){msg ~= contextMark.toString() ~ '\n';} msg ~= problem ~ '\n' ~ problemMark.toString() ~ '\n'; - super(msg); + super(msg, file, line); } //Construct a MarkedYAMLException with specified problem. - this(string problem, Mark problemMark) + this(string problem, Mark problemMark, string file = __FILE__, int line = __LINE__) { - super(problem ~ '\n' ~ problemMark.toString()); + super(problem ~ '\n' ~ problemMark.toString(), file, line); } } + +///Constructors of YAML exceptions are mostly the same, so we use a mixin. +template ExceptionCtors() +{ + public: + this(string msg, string file = __FILE__, int line = __LINE__) + { + super(msg, file, line); + } +} + +///Constructors of marked YAML exceptions are mostly the same, so we use a mixin. +template MarkedExceptionCtors() +{ + public: + this(string context, Mark contextMark, string problem, Mark problemMark, + string file = __FILE__, int line = __LINE__) + { + super(context, contextMark, problem, problemMark, + file, line); + } + + this(string problem, Mark problemMark, string file = __FILE__, int line = __LINE__) + { + super(problem, problemMark, file, line); + } +} diff --git a/dyaml/node.d b/dyaml/node.d index f59c25b..8e7f6c7 100644 --- a/dyaml/node.d +++ b/dyaml/node.d @@ -37,9 +37,9 @@ class NodeException : YAMLException * Params: msg = Error message. * start = Start position of the node. */ - this(string msg, Mark start) + this(string msg, Mark start, string file = __FILE__, int line = __LINE__) { - super(msg ~ "\nNode at:" ~ start.toString()); + super(msg ~ "\nNode at:" ~ start.toString(), file, line); } } diff --git a/dyaml/parser.d b/dyaml/parser.d index a1a08b7..d9e71d3 100644 --- a/dyaml/parser.d +++ b/dyaml/parser.d @@ -96,12 +96,7 @@ package: */ class ParserException : MarkedYAMLException { - this(string context, Mark contextMark, string problem, Mark problemMark) - { - super(context, contextMark, problem, problemMark); - } - - this(string problem, Mark problemMark){super(problem, problemMark);} + mixin MarkedExceptionCtors; } ///Generates events from tokens provided by a Scanner. diff --git a/dyaml/reader.d b/dyaml/reader.d index 85d212b..eda1d36 100644 --- a/dyaml/reader.d +++ b/dyaml/reader.d @@ -27,7 +27,10 @@ package: ///Exception thrown at Reader errors. class ReaderException : YAMLException { - this(string msg){super("Error reading YAML stream: " ~ msg);} + this(string msg, string file = __FILE__, int line = __LINE__) + { + super("Error reading YAML stream: " ~ msg, file, line); + } } ///Reads data from a stream and converts it to UTF-32 (dchar) data. diff --git a/dyaml/representer.d b/dyaml/representer.d index c62ac9b..e90aee8 100644 --- a/dyaml/representer.d +++ b/dyaml/representer.d @@ -30,9 +30,7 @@ import dyaml.tag; ///Exception thrown on Representer errors. class RepresenterException : YAMLException { - public: - ///Construct an RepresenterException with specified message. - this(string msg){super(msg);} + mixin ExceptionCtors; } ///Used to represent YAML nodes various data types into scalar/sequence/mapping nodes ready for output. diff --git a/dyaml/scanner.d b/dyaml/scanner.d index 67a86e0..d8e41d7 100644 --- a/dyaml/scanner.d +++ b/dyaml/scanner.d @@ -61,12 +61,7 @@ package: */ class ScannerException : MarkedYAMLException { - this(string context, Mark contextMark, string problem, Mark problemMark) - { - super(context, contextMark, problem, problemMark); - } - - this(string problem, Mark problemMark){super(problem, problemMark);} + mixin MarkedExceptionCtors; } ///Generates tokens from data provided by a Reader.