JSON Voorhees
Killer JSON for C++
nested_exception.hpp
Go to the documentation of this file.
1 /** \file jsonv/detail/nested_exception.hpp
2 *
3 * Copyright (c) 2015 by Travis Gockel. All rights reserved.
4 *
5 * This program is free software: you can redistribute it and/or modify it under the terms of the Apache License
6 * as published by the Apache Software Foundation, either version 2 of the License, or (at your option) any later
7 * version.
8 *
9 * \author Travis Gockel (travis@gockelhut.com)
10 **/
11 #ifndef __JSONV_DETAIL_NESTED_EXCEPTION_HPP_INCLUDED__
12 #define __JSONV_DETAIL_NESTED_EXCEPTION_HPP_INCLUDED__
13 
14 #include <jsonv/config.hpp>
15 
16 #include <exception>
17 
18 namespace jsonv
19 {
20 
21 #ifdef _MSC_VER
22 
23 /** Component for exception classes that captures the currently handled exception as nested. This class is only used in
24  * Microsoft Visual C++ -- as of MSVC 14 CTP 5, there is no definition for std::nested_exception.
25 **/
26 class JSONV_PUBLIC nested_exception
27 {
28 public:
29  nested_exception() noexcept :
30  _nested(std::current_exception())
31  { }
32 
33  nested_exception(const nested_exception& src) noexcept :
34  _nested(src._nested)
35  { }
36 
37  nested_exception& operator=(const nested_exception& src) noexcept
38  {
39  _nested = src._nested;
40  return *this;
41  }
42 
43  virtual ~nested_exception() noexcept = default;
44 
45  __declspec(noreturn) void rethrow_nested() const
46  {
47  std::rethrow_exception(_nested);
48  }
49 
50  std::exception_ptr nested_ptr() const noexcept
51  {
52  return _nested;
53  }
54 
55 private:
56  std::exception_ptr _nested;
57 };
58 
59 #else
60 
61 using nested_exception = std::nested_exception;
62 
63 #endif
64 
65 }
66 
67 #endif/*__JSONV_DETAIL_NESTED_EXCEPTION_HPP_INCLUDED__*/
STL namespace.
Copyright (c) 2014-2019 by Travis Gockel.
#define JSONV_PUBLIC
This function or class is part of the public API for JsonVoorhees.
Definition: config.hpp:104