blob: 36a63df0568130fd5cf8cafd0b67f99f1d831110 (
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
|
// Copyright (c) 2019 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Ryan Pavlik <ryan.pavlik@collabora.com
//
// Provides protection for C ABI functions if standard library functions may throw.
#pragma once
#include "common_cmake_config.h"
#ifdef XRLOADER_ENABLE_EXCEPTION_HANDLING
#include <stdexcept>
#define XRLOADER_ABI_TRY try
#define XRLOADER_ABI_CATCH_BAD_ALLOC_OOM \
catch (const std::bad_alloc&) { \
LoaderLogger::LogErrorMessage("", "failed allocating memory"); \
return XR_ERROR_OUT_OF_MEMORY; \
}
#define XRLOADER_ABI_CATCH_FALLBACK \
catch (const std::exception& e) { \
LoaderLogger::LogErrorMessage("", "Unknown failure: " + std::string(e.what())); \
return XR_ERROR_RUNTIME_FAILURE; \
} \
catch (...) { \
LoaderLogger::LogErrorMessage("", "Unknown failure"); \
return XR_ERROR_RUNTIME_FAILURE; \
}
#else
#define XRLOADER_ABI_TRY
#define XRLOADER_ABI_CATCH_BAD_ALLOC_OOM
#define XRLOADER_ABI_CATCH_FALLBACK
#endif
|