1 module viva.exceptions.check; 2 3 /++ 4 + Checks a condition 5 + Params: 6 + cond = The condition 7 + message = The user defined exception message 8 + Throws: `Exception` if `cond` is false 9 +/ 10 void check(bool cond, string message) pure @safe 11 { 12 checkBare!Exception(cond, "check failed with message: " ~ message); 13 } 14 15 /++ 16 + Checks a condition 17 + Params: 18 + cond = The condition 19 + message = The user defined exception message 20 + Throws: The given exception (`T`) if `cond` is false 21 +/ 22 void check(T)(bool cond, string message) pure @safe 23 if (is(T : Exception)) 24 { 25 checkBare!T(cond, "check failed with message: " ~ message); 26 } 27 28 /++ 29 + Checks a condition 30 + Params: 31 + cond = The condition 32 + message = The exception message 33 + Throws: `Exception` if `cond` is false 34 +/ 35 void checkBare(bool cond, string message) pure @safe 36 { 37 checkBare!Exception(cond, message); 38 } 39 40 /++ 41 + Checks a condition 42 + Params: 43 + cond = The condition 44 + message = The exception message 45 + Throws: The given exception (`T`) if `cond` is false 46 +/ 47 void checkBare(T)(bool cond, string message) pure @safe 48 if (is(T : Exception)) 49 { 50 if (!cond) 51 throw new T(message); 52 } 53 54 /++ 55 + Checks if 2 values are equals 56 + Params: 57 + obj1 = The first value 58 + obj2 = The second value 59 + message = The user defined exception message 60 + Throws: `Exception` if they're not equals 61 +/ 62 void checkEquals(K, V)(K obj1, V obj2, string message) pure @safe 63 { 64 checkEquals!(Exception, K, V)(obj1, obj2, message); 65 } 66 67 /++ 68 + Checks if 2 values are equals 69 + Params: 70 + obj1 = The first value 71 + obj2 = The second value 72 + message = The user defined exception message 73 + Throws: The given exception (`T`) if they're not equals 74 +/ 75 void checkEquals(T, K, V)(K obj1, V obj2, string message) pure @safe 76 if (is(T : Exception)) 77 { 78 checkBare!(T)(obj1 == obj2, "checkEquals failed with message: " ~ message); 79 } 80 81 /++ 82 + Checks if 2 values are equals 83 + Params: 84 + obj1 = The first value 85 + obj2 = The second value 86 + message = The exception message 87 + Throws: `Exception` if they're not equals 88 +/ 89 void checkEqualsBare(K, V)(K obj1, V obj2, string message) pure @safe 90 { 91 checkEqualsBare!(Exception, K, V)(obj1, obj2, message); 92 } 93 94 /++ 95 + Checks if 2 values are equals 96 + Params: 97 + obj1 = The first value 98 + obj2 = The second value 99 + message = The exception message 100 + Throws: The given exception (`T`) if they're not equals 101 +/ 102 void checkEqualsBare(T, K, V)(K obj1, V obj2, string message) pure @safe 103 if (is(T : Exception)) 104 { 105 checkBare!(T)(obj1 == obj2, message); 106 } 107 108 /++ 109 + Checks if 2 values are not equals 110 + Params: 111 + obj1 = The first value 112 + obj2 = The second value 113 + message = The user defined exception message 114 + Throws: `Exception` if they're equals 115 +/ 116 void checkNotEquals(K, V)(K obj1, V obj2, string message) pure @safe 117 { 118 checkNotEquals!(Exception, K, V)(obj1, obj2, message); 119 } 120 121 /++ 122 + Checks if 2 values are not equals 123 + Params: 124 + obj1 = The first value 125 + obj2 = The second value 126 + message = The user defined exception message 127 + Throws: The given exception (`T`) if they're equals 128 +/ 129 void checkNotEquals(T, K, V)(K obj1, V obj2, string message) pure @safe 130 if (is(T : Exception)) 131 { 132 checkBare!(T)(obj1 != obj2, "checkNotEquals failed with message: " ~ message); 133 } 134 135 /++ 136 + Checks if 2 values are not equals 137 + Params: 138 + obj1 = The first value 139 + obj2 = The second value 140 + message = The exception message 141 + Throws: `Exception` if they're equals 142 +/ 143 void checkNotEqualsBare(K, V)(K obj1, V obj2, string message) pure @safe 144 { 145 checkNotEqualsBare!(Exception, K, V)(obj1, obj2, message); 146 } 147 148 /++ 149 + Checks if 2 values are not equals 150 + Params: 151 + obj1 = The first value 152 + obj2 = The second value 153 + message = The exception message 154 + Throws: The given exception (`T`) if they're equals 155 +/ 156 void checkNotEqualsBare(T, K, V)(K obj1, V obj2, string message) pure @safe 157 if (is(T : Exception)) 158 { 159 checkBare!(T)(obj1 != obj2, message); 160 }