blob: bd3be0937f639eb1c802b8c1e9bc4c40bf640a0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
// Written in the D programming language.
/**
* Interface to C++ <exception>
*
* Copyright: Copyright (c) 2016 D Language Foundation
* License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
* Authors: $(HTTP digitalmars.com, Walter Bright)
* Manu Evans
* Source: $(DRUNTIMESRC core/stdcpp/_exception.d)
*/
module core.stdcpp.exception;
import core.stdcpp.xutility : __cplusplus, CppStdRevision;
import core.attribute : weak;
version (CppRuntime_GNU)
version = GenericBaseException;
version (CppRuntime_LLVM)
version = GenericBaseException;
version (CppRuntime_Sun)
version = GenericBaseException;
extern (C++, "std"):
@nogc:
///
alias terminate_handler = void function() nothrow;
///
terminate_handler set_terminate(terminate_handler f) nothrow;
///
terminate_handler get_terminate() nothrow;
///
void terminate() nothrow;
static if (__cplusplus < CppStdRevision.cpp17)
{
///
alias unexpected_handler = void function();
///
deprecated unexpected_handler set_unexpected(unexpected_handler f) nothrow;
///
deprecated unexpected_handler get_unexpected() nothrow;
///
deprecated void unexpected();
}
static if (__cplusplus < CppStdRevision.cpp17)
{
///
bool uncaught_exception() nothrow;
}
else static if (__cplusplus == CppStdRevision.cpp17)
{
///
deprecated bool uncaught_exception() nothrow;
}
static if (__cplusplus >= CppStdRevision.cpp17)
{
///
int uncaught_exceptions() nothrow;
}
version (GenericBaseException)
{
///
class exception
{
@nogc:
///
extern(D) this() nothrow {}
///
@weak ~this() nothrow {} // HACK: this should extern, but then we have link errors!
///
@weak const(char)* what() const nothrow { return "unknown"; } // HACK: this should extern, but then we have link errors!
protected:
extern(D) this(const(char)*, int = 1) nothrow { this(); } // compat with MS derived classes
}
}
else version (CppRuntime_Microsoft)
{
///
class exception
{
@nogc:
///
extern(D) this(const(char)* message = "unknown", int = 1) nothrow { msg = message; }
///
@weak ~this() nothrow {}
///
@weak const(char)* what() const nothrow { return msg != null ? msg : "unknown exception"; }
// TODO: do we want this? exceptions are classes... ref types.
// final ref exception opAssign(ref const(exception) e) nothrow { msg = e.msg; return this; }
protected:
@weak void _Doraise() const { assert(0); }
protected:
const(char)* msg;
}
}
else
static assert(0, "Missing std::exception binding for this platform");
///
class bad_exception : exception
{
@nogc:
///
extern(D) this(const(char)* message = "bad exception") nothrow { super(message); }
version (GenericBaseException)
{
///
@weak override const(char)* what() const nothrow { return "bad exception"; }
}
}
|