blob: 037b18c4fa73270906155499251394bd9c100cb9 [file] [log] [blame]
Jeff Thompson3d613fd2013-10-15 15:39:04 -07001#ifndef NDNBOOST_DETAIL_NO_EXCEPTIONS_SUPPORT_HPP_
2#define NDNBOOST_DETAIL_NO_EXCEPTIONS_SUPPORT_HPP_
Jeff Thompsona28eed82013-08-22 16:21:10 -07003
4#if (defined _MSC_VER) && (_MSC_VER >= 1200)
5# pragma once
6#endif
7
8//----------------------------------------------------------------------
9// (C) Copyright 2004 Pavel Vozenilek.
10// Use, modification and distribution is subject to the Boost Software
11// License, Version 1.0. (See accompanying file LICENSE_1_0.txt
12// or copy at http://www.boost.org/LICENSE_1_0.txt)
13//
14//
15// This file contains helper macros used when exception support may be
Jeff Thompson3d613fd2013-10-15 15:39:04 -070016// disabled (as indicated by macro NDNBOOST_NO_EXCEPTIONS).
Jeff Thompsona28eed82013-08-22 16:21:10 -070017//
18// Before picking up these macros you may consider using RAII techniques
19// to deal with exceptions - their syntax can be always the same with
20// or without exception support enabled.
21//
22
23/* Example of use:
24
25void foo() {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070026 NDNBOOST_TRY {
Jeff Thompsona28eed82013-08-22 16:21:10 -070027 ...
Jeff Thompson3d613fd2013-10-15 15:39:04 -070028 } NDNBOOST_CATCH(const std::bad_alloc&) {
Jeff Thompsona28eed82013-08-22 16:21:10 -070029 ...
Jeff Thompson3d613fd2013-10-15 15:39:04 -070030 NDNBOOST_RETHROW
31 } NDNBOOST_CATCH(const std::exception& e) {
Jeff Thompsona28eed82013-08-22 16:21:10 -070032 ...
33 }
Jeff Thompson3d613fd2013-10-15 15:39:04 -070034 NDNBOOST_CATCH_END
Jeff Thompsona28eed82013-08-22 16:21:10 -070035}
36
37With exception support enabled it will expand into:
38
39void foo() {
40 { try {
41 ...
42 } catch (const std::bad_alloc&) {
43 ...
44 throw;
45 } catch (const std::exception& e) {
46 ...
47 }
48 }
49}
50
51With exception support disabled it will expand into:
52
53void foo() {
54 { if(true) {
55 ...
56 } else if (false) {
57 ...
58 } else if (false) {
59 ...
60 }
61 }
62}
63*/
64//----------------------------------------------------------------------
65
66#include <ndnboost/config.hpp>
67#include <ndnboost/detail/workaround.hpp>
68
Jeff Thompson3d613fd2013-10-15 15:39:04 -070069#if !(defined NDNBOOST_NO_EXCEPTIONS)
70# define NDNBOOST_TRY { try
71# define NDNBOOST_CATCH(x) catch(x)
72# define NDNBOOST_RETHROW throw;
73# define NDNBOOST_CATCH_END }
Jeff Thompsona28eed82013-08-22 16:21:10 -070074#else
Jeff Thompson3d613fd2013-10-15 15:39:04 -070075# if NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x564))
76# define NDNBOOST_TRY { if ("")
77# define NDNBOOST_CATCH(x) else if (!"")
Jeff Thompsona28eed82013-08-22 16:21:10 -070078# else
Jeff Thompson3d613fd2013-10-15 15:39:04 -070079# define NDNBOOST_TRY { if (true)
80# define NDNBOOST_CATCH(x) else if (false)
Jeff Thompsona28eed82013-08-22 16:21:10 -070081# endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -070082# define NDNBOOST_RETHROW
83# define NDNBOOST_CATCH_END }
Jeff Thompsona28eed82013-08-22 16:21:10 -070084#endif
85
86
87#endif