Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
Exception.h
Go to the documentation of this file.
1 //===-- serialbox/core/Exception.h --------------------------------------------------*- C++ -*-===//
2 //
3 // S E R I A L B O X
4 //
5 // This file is distributed under terms of BSD license.
6 // See LICENSE.txt for more information
7 //
8 //===------------------------------------------------------------------------------------------===//
9 //
13 //===------------------------------------------------------------------------------------------===//
14 
15 #ifndef SERIALBOX_CORE_EXCEPTION_H
16 #define SERIALBOX_CORE_EXCEPTION_H
17 
18 #include <boost/format.hpp>
19 #include <stdexcept>
20 
21 namespace serialbox {
22 
25 
30 class Exception : public std::runtime_error {
31 public:
36  template <typename... Args>
37  Exception(const char* fmt, Args&&... args)
38  : std::runtime_error(formatVargs(fmt, std::forward<Args>(args)...)) {}
39 
40 private:
41  template <typename... Args>
42  std::string formatVargs(const std::string& fmt, Args&&... args) {
43  boost::format f(fmt);
44  int unroll[]{0, (f % std::forward<Args>(args), 0)...};
45  static_cast<void>(unroll);
46  return boost::str(f);
47  }
48 };
49 
51 
52 } // namespace serialbox
53 
54 #endif
Definition: json.hpp:10517
Namespace of the serialbox library.
Definition: Archive.h:25
Exception class which stores a human-readable error description.
Definition: Exception.h:30
Exception(const char *fmt, Args &&... args)
Variadic constructor to support printf-style arguments.
Definition: Exception.h:37