From 0d5b7c42e4c4999b803b7efefb9a3112fb39424b Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 18 Nov 2023 11:11:37 +0200 Subject: [PATCH] Exceptions - Added `DanteException` - Added `ProtocolException` - Added `CommandException` --- source/dante/exceptions.d | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 source/dante/exceptions.d diff --git a/source/dante/exceptions.d b/source/dante/exceptions.d new file mode 100644 index 0000000..bd2885f --- /dev/null +++ b/source/dante/exceptions.d @@ -0,0 +1,43 @@ +module dante.exceptions; + +public abstract class DanteException : Exception +{ + this(string msg) + { + super(msg); + } +} + +public class CommandException : DanteException +{ + this(string msg) + { + super(msg); + } +} + +import std.conv : to; + +public class ProtocolException : DanteException +{ + this(string msg) + { + super(msg); + } + + public static ProtocolException expectedMessageKind(TypeInfo_Class expected, Object got) + { + string message = "Expected message of type '"~to!(string)(expected); + + if(got is null) + { + message ~= " but got null"; + } + else + { + message ~= " but got a message of type '"~to!(string)(got.classinfo)~"'"; + } + + return new ProtocolException(message); + } +} \ No newline at end of file