egra: agg mini code cleanups
[iv.d.git] / _obsolete_dont_use / exex.d
blobc437eee094925aaaf47b272d958dceffd38cc30a
1 /* Invisible Vector Library
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // severely outdated exception helpers
18 module iv.exex /*is aliced*/;
19 import iv.alice;
22 // ////////////////////////////////////////////////////////////////////////// //
23 mixin template ExceptionCtor() {
24 static if (__VERSION__ > 2067) {
25 this (string msg, string file=__FILE__, usize line=__LINE__, Throwable next=null) @safe pure nothrow @nogc {
26 super(msg, file, line, next);
28 } else {
29 this (string msg, string file=__FILE__, usize line=__LINE__, Throwable next=null) @safe pure nothrow {
30 super(msg, file, line, next);
36 // usage:
37 // mixin(MyException!"MyEx");
38 // mixin(MyException!("MyEx1", "MyEx"));
39 enum MyException(string name, string base="Exception") = `class `~name~` : `~base~` { mixin ExceptionCtor; }`;
42 mixin(MyException!"IVException");
43 mixin(MyException!("IVNamedExceptionBase", "IVException"));
44 mixin(MyException!("IVNamedException(string name)", "IVNamedExceptionBase"));
47 version(test_exex)
48 unittest {
49 import iv.writer;
51 void testit (void delegate () dg) {
52 try {
53 dg();
54 } catch (IVNamedException!"Alice" e) {
55 writeln("from Alice: ", e.msg);
56 } catch (IVNamedException!"Miriel" e) {
57 writeln("from Miriel: ", e.msg);
58 } catch (IVException e) {
59 writeln("from IV: ", e.msg);
63 testit({ throw new IVException("msg"); });
64 testit({ throw new IVNamedException!"Alice"("Hi, I'm Alice!"); });
65 testit({ throw new IVNamedException!"Miriel"("Hi, I'm Miriel!"); });