Manticore  Version 1.0
Physics of Molecular Clouds
Classes | Namespaces | Macros | Functions
Exception.h File Reference

Defines the Exception base class. More...

#include <exception>
#include "mutils/Log.h"
Include dependency graph for Exception.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  mutils::Exception
 MathUtils exception (base) class. More...
 

Namespaces

 mutils
 MathUtils package.
 

Macros

#define MU_EXCEPTION(src, msg, ...)
 Throws mutils::Exception using uniform messaging. More...
 
#define MU_EXCEPTION_ERRNO(src, msg, ...)
 Throws mutils::Exception using uniform messaging (including errno text). More...
 
#define MU_EXCEPTION_ERRNO_IF(cond, src, msg, ...)
 Conditionally throws mutils::Exception (including errno text). More...
 
#define MU_EXCEPTION_IF(cond, src, msg, ...)
 Conditionally throws mutils::Exception. More...
 
#define MU_RETHROW(ex, src, msg, ...)
 Rethrows an exception with a new message (after logging the original one). More...
 
#define MU_THROW(ex, src, msg, ...)
 Throws an exception using uniform messaging. More...
 
#define MU_THROW_ERRNO(ex, src, msg, ...)   MU_THROW(ex, src, msg ": %s", ## __VA_ARGS__, strerror(errno))
 Throws an exception using uniform messaging (including errno text). More...
 
#define MU_THROW_ERRNO_IF(cond, ex, src, msg, ...)   MU_THROW_IF(cond, ex, src, msg ": %s", ## __VA_ARGS__, strerror(errno))
 Conditionally throws an exception (including errno text). More...
 
#define MU_THROW_IF(cond, ex, src, msg, ...)
 Conditionally throws an exception. More...
 

Functions

void mutils::exitException (std::exception &ex, int status=EXIT_FAILURE)
 Exits program with exception message. Exits the program (with status) after displaying the exception ex. More...
 
void mutils::printException (std::exception &ex)
 Prints exception message. More...
 

Detailed Description

Defines the Exception base class.

Author:  Kevin P. Rauch  <rauch.nosp@m.@ast.nosp@m.ro.um.nosp@m.d.ed.nosp@m.u>

Definition in file Exception.h.

Macro Definition Documentation

◆ MU_EXCEPTION

#define MU_EXCEPTION (   src,
  msg,
  ... 
)
Value:
do { \
mutils::Exception _mu_ex; \
MU_THROW(_mu_ex, src, msg, ## __VA_ARGS__); \
} while (0)

Throws mutils::Exception using uniform messaging.

Parameters
[in]srcError source (function or method).
[in]msgError message format string.
[in]...Optional arguments to satisfy sprintf(msg, ...) call.
Warning
This must be defined as a macro to get proper line information.

Definition at line 90 of file Exception.h.

Referenced by manticore::SPIRE::init(), manticore::PACS::init(), and manticore::setKeys().

◆ MU_EXCEPTION_ERRNO

#define MU_EXCEPTION_ERRNO (   src,
  msg,
  ... 
)
Value:
do { \
mutils::Exception _mu_ex; \
MU_THROW_ERRNO(_mu_ex, src, msg, ## __VA_ARGS__); \
} while (0)

Throws mutils::Exception using uniform messaging (including errno text).

Parameters
[in]srcError source (function or method).
[in]msgError message format string.
[in]...Optional arguments to satisfy sprintf(msg, ...) call.
Warning
This must be defined as a macro to get proper line information. This macro is not thread-safe.

Definition at line 112 of file Exception.h.

◆ MU_EXCEPTION_ERRNO_IF

#define MU_EXCEPTION_ERRNO_IF (   cond,
  src,
  msg,
  ... 
)
Value:
do { \
mutils::Exception _mu_ex; \
MU_THROW_ERRNO_IF(cond, _mu_ex, src, msg, ## __VA_ARGS__); \
} while (0)

Conditionally throws mutils::Exception (including errno text).

Parameters
[in]condFailure test condition.
[in]srcError source (function or method).
[in]msgError message format string.
[in]...Optional arguments to satisfy sprintf(msg, ...) call.
Warning
This must be defined as a macro to get proper line information. This macro is not thread-safe.

Definition at line 124 of file Exception.h.

Referenced by main().

◆ MU_EXCEPTION_IF

#define MU_EXCEPTION_IF (   cond,
  src,
  msg,
  ... 
)
Value:
do { \
mutils::Exception _mu_ex; \
MU_THROW_IF(cond, _mu_ex, src, msg, ## __VA_ARGS__); \
} while (0)

Conditionally throws mutils::Exception.

Parameters
[in]condFailure test condition.
[in]srcError source (function or method).
[in]msgError message format string.
[in]...Optional arguments to satisfy sprintf(msg, ...) call.
Warning
This must be defined as a macro to get proper line information.

Definition at line 101 of file Exception.h.

Referenced by manticore::getError(), mutils::CommandLine::getInteger(), mutils::CommandLine::getOption(), main(), mutils::CommandLine::parseLong(), mutils::CommandLine::parseShort(), and manticore::process().

◆ MU_RETHROW

#define MU_RETHROW (   ex,
  src,
  msg,
  ... 
)
Value:
do { \
(ex).print(); MU_THROW(ex, src, msg, ## __VA_ARGS__); \
} while (0)
#define MU_THROW(ex, src, msg,...)
Throws an exception using uniform messaging.
Definition: Exception.h:24

Rethrows an exception with a new message (after logging the original one).

Parameters
[in]exException object (must be lvalue).
[in]srcError source (function or method).
[in]msgError message format string.
[in]...Optional arguments to satisfy sprintf(msg, ...) call.
Warning
The exception ex must be or derive from mutils::Exception. This must be defined as a macro to get proper line information.

Definition at line 44 of file Exception.h.

◆ MU_THROW

#define MU_THROW (   ex,
  src,
  msg,
  ... 
)
Value:
do { \
char _mu_buf[4096]; \
mutils::cxxsnprintf(_mu_buf, sizeof(_mu_buf), "%s:%0*d: " msg "\n", \
(db ? (src) : ""), (db ? 1 : 4), __LINE__, ## __VA_ARGS__); \
} else { \
(ex).message(_mu_buf); \
throw (ex); \
} \
} while (0)
static bool errors
Whether to print error messages (else throw exceptions).
Definition: Exception.h:182
static int error(Args &&... args)
Logs a message at level ERROR.
Definition: Log.h:408
int cxxsnprintf(char *buf, size_t len, Args &&... args)
C snprintf() with type conversion (not safety).
Definition: Log.h:297
static int level
Message logging level for output to stream.
Definition: Log.h:430
static constexpr int DEBUG
Verbose information.
Definition: Log.h:350

Throws an exception using uniform messaging.

Parameters
[in]exException object (must be lvalue).
[in]srcError source (function or method).
[in]msgError message format string.
[in]...Optional arguments to satisfy sprintf(msg, ...) call.
Note
If mutils::Exception::errors is set the exception is not thrown, only an error message is printed.
Warning
The exception ex must be or derive from mutils::Exception. This must be defined as a macro to get proper line information.

Definition at line 24 of file Exception.h.

◆ MU_THROW_ERRNO

#define MU_THROW_ERRNO (   ex,
  src,
  msg,
  ... 
)    MU_THROW(ex, src, msg ": %s", ## __VA_ARGS__, strerror(errno))

Throws an exception using uniform messaging (including errno text).

Parameters
[in]exException object (must be lvalue).
[in]srcError source (function or method).
[in]msgError message format string.
[in]...Optional arguments to satisfy sprintf(msg, ...) call.
Warning
The exception ex must be or derive from mutils::Exception. This must be defined as a macro to get proper line information. This macro is not thread-safe.

Definition at line 69 of file Exception.h.

◆ MU_THROW_ERRNO_IF

#define MU_THROW_ERRNO_IF (   cond,
  ex,
  src,
  msg,
  ... 
)    MU_THROW_IF(cond, ex, src, msg ": %s", ## __VA_ARGS__, strerror(errno))

Conditionally throws an exception (including errno text).

Parameters
[in]condFailure test condition.
[in]exException object (must be lvalue).
[in]srcError source (function or method).
[in]msgError message format string.
[in]...Optional arguments to satisfy sprintf(msg, ...) call.
Warning
The exception ex must be or derive from mutils::Exception. This must be defined as a macro to get proper line information. This macro is not thread-safe.

Definition at line 81 of file Exception.h.

◆ MU_THROW_IF

#define MU_THROW_IF (   cond,
  ex,
  src,
  msg,
  ... 
)
Value:
do { \
if (cond) { MU_THROW(ex, src, msg, ## __VA_ARGS__); } \
} while (0)
#define MU_THROW(ex, src, msg,...)
Throws an exception using uniform messaging.
Definition: Exception.h:24

Conditionally throws an exception.

Parameters
[in]condFailure test condition.
[in]exException object (must be lvalue).
[in]srcError source (function or method).
[in]msgError message format string.
[in]...Optional arguments to satisfy sprintf(msg, ...) call.
Warning
The exception ex must be or derive from mutils::Exception. This must be defined as a macro to get proper line information.

Definition at line 56 of file Exception.h.