CernVM-FS  2.13.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)) void Panic(const char *coordinates,
33  const LogSource source, const int mask,
34  const char *format, ...);
35 
36 // For PANIC(NULL)
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 static inline bool AssertOrLog(int t, const LogSource /*log_source*/,
61  const int /*log_mask*/,
62  const char * /*log_msg_format*/, ...) {
63  assert(t);
64  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_
CVMFS_EXPORT const LogSource const int mask
Definition: exception.h:33
CVMFS_EXPORT const LogSource source
Definition: exception.h:33
CVMFS_EXPORT void vLogCvmfs(const LogSource source, const int mask, const char *format, va_list variadic_list)
Definition: logging.cc:422
#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:60
LogSource
CVMFS_EXPORT const LogSource const int const char CVMFS_EXPORT const LogSource const char * nul
Definition: exception.h:39
CVMFS_EXPORT const LogSource const int const char * format
Definition: exception.h:33
ECvmfsException(const std::string &what_arg)
Definition: exception.h:22