aboutsummaryrefslogtreecommitdiffstats
path: root/common/alexcpt.h
blob: 654520cbdf0a48787c26ee2333aebf95952c0dcf (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
#ifndef ALEXCPT_H
#define ALEXCPT_H

#include <exception>
#include <string>

#include "AL/alc.h"


#ifdef __GNUC__
#define ALEXCPT_FORMAT(x, y, z) __attribute__((format(x, (y), (z))))
#else
#define ALEXCPT_FORMAT(x, y, z)
#endif


namespace al {

class backend_exception final : public std::exception {
    std::string mMessage;
    ALCenum mErrorCode;

public:
    backend_exception(ALCenum code, const char *msg, ...) ALEXCPT_FORMAT(printf, 3,4);

    const char *what() const noexcept override { return mMessage.c_str(); }
    ALCenum errorCode() const noexcept { return mErrorCode; }
};

} // namespace al

#define START_API_FUNC try

#ifndef _MSC_VER
#define END_API_FUNC catch(...) { std::terminate(); }
#else
/* VS 2015 complains that some of these catch statements are unreachable code,
 * due to the function body not able to throw anything. While technically true,
 * it's preferable to mark API functions just in case that ever changes, so
 * silence that warning.
 */
#define END_API_FUNC __pragma(warning(push)) \
__pragma(warning(disable : 4702))            \
catch(...) { std::terminate(); }             \
__pragma(warning(pop))
#endif

#endif /* ALEXCPT_H */