Exceptions

- Added `DeserializationError`

Deserializer

- On error now throws `DeserializationError` exception
This commit is contained in:
Tristan B. Velloza Kildaire 2023-06-28 11:51:57 +02:00
parent 2f4570d0fa
commit dad7e04ccf
2 changed files with 11 additions and 4 deletions

View File

@ -4,7 +4,7 @@
module jstruct.deserializer;
import std.json;
import jstruct.exceptions : SerializationError;
import jstruct.exceptions : DeserializationError;
import std.traits : FieldTypeTuple, FieldNameTuple, isArray;
/**
@ -191,8 +191,7 @@ public RecordType fromJSON(RecordType)(JSONValue jsonIn)
}
catch(JSONException e)
{
// TOOD: Should be DEserialization error
throw new SerializationError();
throw new DeserializationError();
}
}
@ -287,7 +286,7 @@ unittest
Person person = fromJSON!(Person)(json);
assert(false);
}
catch(SerializationError)
catch(DeserializationError)
{
assert(true);
}

View File

@ -15,3 +15,11 @@ public final class SerializationError : JStructException
super("Error serializing");
}
}
public final class DeserializationError : JStructException
{
this()
{
super("Error deserializing");
}
}