Exceptions

- Added `DanteException`
- Added `ProtocolException`
- Added `CommandException`
This commit is contained in:
Tristan B. Velloza Kildaire 2023-11-18 11:11:37 +02:00
parent 8040bde4e9
commit 0d5b7c42e4
1 changed files with 43 additions and 0 deletions

43
source/dante/exceptions.d Normal file
View File

@ -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);
}
}