]> git.ipfire.org Git - thirdparty/gcc.git/blob - libphobos/testsuite/libphobos.exceptions/future_message.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / libphobos / testsuite / libphobos.exceptions / future_message.d
1 // { dg-options "-Wno-deprecated" }
2 import core.stdc.stdio;
3
4 // Make sure basic stuff works with future Throwable.message
5 class NoMessage : Throwable
6 {
7 @nogc @safe pure nothrow this(string msg, Throwable next = null)
8 {
9 super(msg, next);
10 }
11 }
12
13 class WithMessage : Throwable
14 {
15 @nogc @safe pure nothrow this(string msg, Throwable next = null)
16 {
17 super(msg, next);
18 }
19
20 override const(char)[] message() const
21 {
22 return "I have a custom message.";
23 }
24 }
25
26 class WithMessageNoOverride : Throwable
27 {
28 @nogc @safe pure nothrow this(string msg, Throwable next = null)
29 {
30 super(msg, next);
31 }
32
33 const(char)[] message() const
34 {
35 return "I have a custom message and no override.";
36 }
37 }
38
39 class WithMessageNoOverrideAndDifferentSignature : Throwable
40 {
41 @nogc @safe pure nothrow this(string msg, Throwable next = null)
42 {
43 super(msg, next);
44 }
45
46 immutable(char)[] message()
47 {
48 return "I have a custom message and I'm nothing like Throwable.message.";
49 }
50 }
51
52 void test(Throwable t)
53 {
54 try
55 {
56 throw t;
57 }
58 catch (Throwable e)
59 {
60 fprintf(stderr, "%.*s ", cast(int)e.message.length, e.message.ptr);
61 }
62 }
63
64 void main()
65 {
66 test(new NoMessage("exception"));
67 test(new WithMessage("exception"));
68 test(new WithMessageNoOverride("exception"));
69 test(new WithMessageNoOverrideAndDifferentSignature("exception"));
70 fprintf(stderr, "\n");
71 }