CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
exception.cc
Go to the documentation of this file.
1 
5 #include "cvmfs_config.h"
6 #include "exception.h"
7 
8 #include <cassert>
9 #include <cstdarg>
10 #include <cstdio>
11 #include <cstdlib>
12 
13 #include "util/logging.h"
14 
15 #ifdef CVMFS_NAMESPACE_GUARD
16 namespace CVMFS_NAMESPACE_GUARD {
17 #endif
18 
19 void Panic(const char* coordinates, const LogSource source, const int mask,
20  const char* format, ...) {
21  char* msg = NULL;
22  va_list variadic_list;
23 
24  // Format the message string
25  va_start(variadic_list, format);
26  int retval = vasprintf(&msg, format, variadic_list);
27  assert(retval != -1); // else: out of memory
28  va_end(variadic_list);
29 
30  // Add the coordinates
31  char* msg_with_coordinates = NULL;
32  retval = asprintf(&msg_with_coordinates, "%s\n%s", coordinates, msg);
33  if (retval == -1) {
34  free(msg_with_coordinates);
35  } else {
36  free(msg);
37  msg = msg_with_coordinates;
38  }
39  // From now on we deal only with `msg`
40 
41  // Either throw the exception or log + abort
42 #ifdef CVMFS_RAISE_EXCEPTIONS
43  (void) source;
44  (void) mask;
45  throw ECvmfsException(msg);
46 #else
47  LogCvmfs(source, mask, "%s", msg);
48  abort();
49 #endif
50 }
51 
52 void Panic(const char* coordinates, const LogSource _source, const char *nul) {
53  assert(nul == NULL);
54  Panic(coordinates, _source, kLogDebug | kLogStderr | kLogSyslogErr, "");
55 }
56 
57 #ifdef CVMFS_NAMESPACE_GUARD
58 } // namespace CVMFS_NAMESPACE_GUARD
59 #endif
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
LogSource
const int const char * format
Definition: logging.h:23
const int mask
Definition: logging.h:23
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:528