CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
exception.h
Go to the documentation of this file.
1 
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  explicit ECvmfsException(const std::string& what_arg)
23  : 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 
32 __attribute__((noreturn))
33 void Panic(const char *coordinates, const LogSource source, const int mask,
34  const char *format, ...);
35 
36 // For PANIC(NULL)
38 __attribute__((noreturn))
39 void Panic(const char *coordinates, 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,
48  const LogSource log_source,
49  const int log_mask,
50  const char *log_msg_format, ...) {
51  if (!t) {
52  va_list variadic_list;
53  va_start(variadic_list, log_msg_format);
54  vLogCvmfs(log_source, log_mask, log_msg_format, variadic_list);
55  va_end(variadic_list);
56  return false;
57  }
58  return true;
59 }
60 #else
61 static inline bool AssertOrLog(int t,
62  const LogSource /*log_source*/,
63  const int /*log_mask*/,
64  const char* /*log_msg_format*/, ...) {
65  assert(t);
66  return true;
67 }
68 #endif
69 
70 #ifdef CVMFS_NAMESPACE_GUARD
71 } // namespace CVMFS_NAMESPACE_GUARD
72 #endif
73 
74 #endif // CVMFS_UTIL_EXCEPTION_H_
CVMFS_EXPORT void vLogCvmfs(const LogSource source, const int mask, const char *format, va_list variadic_list)
Definition: logging.cc:423
#define CVMFS_EXPORT
Definition: export.h:11
assert((mem||(size==0))&&"Out Of Memory")
void Panic(const char *coordinates, const LogSource source, const int mask, const char *format,...)
Definition: exception.cc:19
struct cvmcache_object_info __attribute__
Definition: atomic.h:24
static bool AssertOrLog(int t, const LogSource, const int, const char *,...)
Definition: exception.h:61
LogSource
const int const char * format
Definition: logging.h:23
const int mask
Definition: logging.h:23
ECvmfsException(const std::string &what_arg)
Definition: exception.h:22