Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/openxr/src/loader/exception_handling.hpp
9917 views
1
// Copyright (c) 2019-2025 The Khronos Group Inc.
2
//
3
// SPDX-License-Identifier: Apache-2.0 OR MIT
4
//
5
// Initial Author: Rylie Pavlik <[email protected]>
6
//
7
// Provides protection for C ABI functions if standard library functions may throw.
8
9
#pragma once
10
11
#ifdef OPENXR_HAVE_COMMON_CONFIG
12
#include "common_config.h"
13
#endif // OPENXR_HAVE_COMMON_CONFIG
14
15
#ifdef XRLOADER_DISABLE_EXCEPTION_HANDLING
16
17
#define XRLOADER_ABI_TRY
18
#define XRLOADER_ABI_CATCH_BAD_ALLOC_OOM
19
#define XRLOADER_ABI_CATCH_FALLBACK
20
21
#else
22
23
#include <stdexcept>
24
#define XRLOADER_ABI_TRY try
25
#define XRLOADER_ABI_CATCH_BAD_ALLOC_OOM \
26
catch (const std::bad_alloc&) { \
27
LoaderLogger::LogErrorMessage("", "failed allocating memory"); \
28
return XR_ERROR_OUT_OF_MEMORY; \
29
}
30
#define XRLOADER_ABI_CATCH_FALLBACK \
31
catch (const std::exception& e) { \
32
LoaderLogger::LogErrorMessage("", "Unknown failure: " + std::string(e.what())); \
33
return XR_ERROR_RUNTIME_FAILURE; \
34
} \
35
catch (...) { \
36
LoaderLogger::LogErrorMessage("", "Unknown failure"); \
37
return XR_ERROR_RUNTIME_FAILURE; \
38
}
39
40
#endif
41
42