| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* This file is part of the CernVM File System. |
| 3 |
|
|
*/ |
| 4 |
|
|
|
| 5 |
|
|
#ifndef CVMFS_UTIL_EXCEPTION_H_ |
| 6 |
|
|
#define CVMFS_UTIL_EXCEPTION_H_ |
| 7 |
|
|
|
| 8 |
|
|
#include <cassert> |
| 9 |
|
|
#include <cstdarg> |
| 10 |
|
|
#include <stdexcept> |
| 11 |
|
|
#include <string> |
| 12 |
|
|
|
| 13 |
|
|
#include "util/export.h" |
| 14 |
|
|
#include "util/logging.h" |
| 15 |
|
|
|
| 16 |
|
|
#ifdef CVMFS_NAMESPACE_GUARD |
| 17 |
|
|
namespace CVMFS_NAMESPACE_GUARD { |
| 18 |
|
|
#endif |
| 19 |
|
|
|
| 20 |
|
|
class CVMFS_EXPORT ECvmfsException : public std::runtime_error { |
| 21 |
|
|
public: |
| 22 |
|
904 |
explicit ECvmfsException(const std::string &what_arg) |
| 23 |
|
904 |
: std::runtime_error(what_arg) { } |
| 24 |
|
|
}; |
| 25 |
|
|
|
| 26 |
|
|
#define CVMFS_S1(x) #x |
| 27 |
|
|
#define CVMFS_S2(x) CVMFS_S1(x) |
| 28 |
|
|
#define CVMFS_SOURCE_LOCATION "PANIC: " __FILE__ " : " CVMFS_S2(__LINE__) |
| 29 |
|
|
#define PANIC(...) Panic(CVMFS_SOURCE_LOCATION, kLogCvmfs, __VA_ARGS__); |
| 30 |
|
|
|
| 31 |
|
|
CVMFS_EXPORT |
| 32 |
|
|
__attribute__((noreturn)) void Panic(const char *coordinates, |
| 33 |
|
|
const LogSource source, const int mask, |
| 34 |
|
|
const char *format, ...); |
| 35 |
|
|
|
| 36 |
|
|
// For PANIC(NULL) |
| 37 |
|
|
CVMFS_EXPORT |
| 38 |
|
|
__attribute__((noreturn)) void Panic(const char *coordinates, |
| 39 |
|
|
const LogSource source, const char *nul); |
| 40 |
|
|
|
| 41 |
|
|
// The AssertOrLog function is used for rare error cases that are not yet fully |
| 42 |
|
|
// understood. By default, these error cases are considered as unreachable and |
| 43 |
|
|
// thus an assert is thrown. Some users may prefer though to continue operation |
| 44 |
|
|
// (even though the file system state may be scrambled). |
| 45 |
|
|
// Ideally, we can at some point remove all AssertOrLog statements. |
| 46 |
|
|
#ifdef CVMFS_SUPPRESS_ASSERTS |
| 47 |
|
|
static inline bool AssertOrLog(int t, const LogSource log_source, |
| 48 |
|
|
const int log_mask, const char *log_msg_format, |
| 49 |
|
|
...) { |
| 50 |
|
|
if (!t) { |
| 51 |
|
|
va_list variadic_list; |
| 52 |
|
|
va_start(variadic_list, log_msg_format); |
| 53 |
|
|
vLogCvmfs(log_source, log_mask, log_msg_format, variadic_list); |
| 54 |
|
|
va_end(variadic_list); |
| 55 |
|
|
return false; |
| 56 |
|
|
} |
| 57 |
|
|
return true; |
| 58 |
|
|
} |
| 59 |
|
|
#else |
| 60 |
|
254 |
static inline bool AssertOrLog(int t, const LogSource /*log_source*/, |
| 61 |
|
|
const int /*log_mask*/, |
| 62 |
|
|
const char * /*log_msg_format*/, ...) { |
| 63 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 254 times.
|
254 |
assert(t); |
| 64 |
|
254 |
return true; |
| 65 |
|
|
} |
| 66 |
|
|
#endif |
| 67 |
|
|
|
| 68 |
|
|
#ifdef CVMFS_NAMESPACE_GUARD |
| 69 |
|
|
} // namespace CVMFS_NAMESPACE_GUARD |
| 70 |
|
|
#endif |
| 71 |
|
|
|
| 72 |
|
|
#endif // CVMFS_UTIL_EXCEPTION_H_ |
| 73 |
|
|
|