iv.vfs: "z" in file mode now means "unconditionally use gzip"; made mode parser simplier
[iv.d.git] / _obsolete_dont_use / exex.d
blobc63abc049dcf18f132e46fd24d1ad8ab80d072b8
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, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // severely outdated exception helpers
19 module iv.exex /*is aliced*/;
20 import iv.alice;
23 // ////////////////////////////////////////////////////////////////////////// //
24 mixin template ExceptionCtor() {
25 static if (__VERSION__ > 2067) {
26 this (string msg, string file=__FILE__, usize line=__LINE__, Throwable next=null) @safe pure nothrow @nogc {
27 super(msg, file, line, next);
29 } else {
30 this (string msg, string file=__FILE__, usize line=__LINE__, Throwable next=null) @safe pure nothrow {
31 super(msg, file, line, next);
37 // usage:
38 // mixin(MyException!"MyEx");
39 // mixin(MyException!("MyEx1", "MyEx"));
40 enum MyException(string name, string base="Exception") = `class `~name~` : `~base~` { mixin ExceptionCtor; }`;
43 mixin(MyException!"IVException");
44 mixin(MyException!("IVNamedExceptionBase", "IVException"));
45 mixin(MyException!("IVNamedException(string name)", "IVNamedExceptionBase"));
48 version(test_exex)
49 unittest {
50 import iv.writer;
52 void testit (void delegate () dg) {
53 try {
54 dg();
55 } catch (IVNamedException!"Alice" e) {
56 writeln("from Alice: ", e.msg);
57 } catch (IVNamedException!"Miriel" e) {
58 writeln("from Miriel: ", e.msg);
59 } catch (IVException e) {
60 writeln("from IV: ", e.msg);
64 testit({ throw new IVException("msg"); });
65 testit({ throw new IVNamedException!"Alice"("Hi, I'm Alice!"); });
66 testit({ throw new IVNamedException!"Miriel"("Hi, I'm Miriel!"); });