From b19a2445e94ac9770bc72682bbc48e0efc99e30a Mon Sep 17 00:00:00 2001 From: Stefnotch Date: Mon, 4 Nov 2019 09:46:17 +0100 Subject: [PATCH] Improve exception messages --- Source/Editor/Assert.cs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/Source/Editor/Assert.cs b/Source/Editor/Assert.cs index 605982f..bd49798 100644 --- a/Source/Editor/Assert.cs +++ b/Source/Editor/Assert.cs @@ -21,15 +21,34 @@ public SuccessException(string message, Exception innerException) : base(message } } + /// + /// Exception thrown when an assertion fails + /// + /// + public class AssertException : Exception + { + public AssertException() + { + } + + public AssertException(string message) : base(message) + { + } + + public AssertException(string message, Exception innerException) : base(message, innerException) + { + } + } + public static class Assert { public static void Pass() => throw new SuccessException(); - public static void Fail() => throw new Exception(); + public static void Fail() => throw new AssertException("Fail"); - public static void AreEqual(object a, object b) { if (!Equals(a, b)) throw new Exception(); } - public static void AreNotEqual(object a, object b) { if (Equals(a, b)) throw new Exception(); } + public static void AreEqual(object a, object b) { if (!Equals(a, b)) throw new AssertException($"{a} does not equal {b}"); } + public static void AreNotEqual(object a, object b) { if (Equals(a, b)) throw new Exception($"{a} is equal to {b}"); } - public static void True(bool a) { if (!a) throw new Exception(); } - public static void False(bool a) { if (a) throw new Exception(); } + public static void True(bool a) { if (!a) throw new Exception($"{a} is not true"); } + public static void False(bool a) { if (a) throw new Exception($"{a} is not false"); } } } \ No newline at end of file