Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 1 | #ifndef NDNBOOST_DETAIL_NO_EXCEPTIONS_SUPPORT_HPP_ |
| 2 | #define NDNBOOST_DETAIL_NO_EXCEPTIONS_SUPPORT_HPP_ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 3 | |
| 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 16 | // disabled (as indicated by macro NDNBOOST_NO_EXCEPTIONS). |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 17 | // |
| 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 | |
| 25 | void foo() { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 26 | NDNBOOST_TRY { |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 27 | ... |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 28 | } NDNBOOST_CATCH(const std::bad_alloc&) { |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 29 | ... |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 30 | NDNBOOST_RETHROW |
| 31 | } NDNBOOST_CATCH(const std::exception& e) { |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 32 | ... |
| 33 | } |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 34 | NDNBOOST_CATCH_END |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | With exception support enabled it will expand into: |
| 38 | |
| 39 | void foo() { |
| 40 | { try { |
| 41 | ... |
| 42 | } catch (const std::bad_alloc&) { |
| 43 | ... |
| 44 | throw; |
| 45 | } catch (const std::exception& e) { |
| 46 | ... |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | With exception support disabled it will expand into: |
| 52 | |
| 53 | void 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 69 | #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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 74 | #else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 75 | # if NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x564)) |
| 76 | # define NDNBOOST_TRY { if ("") |
| 77 | # define NDNBOOST_CATCH(x) else if (!"") |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 78 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 79 | # define NDNBOOST_TRY { if (true) |
| 80 | # define NDNBOOST_CATCH(x) else if (false) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 81 | # endif |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 82 | # define NDNBOOST_RETHROW |
| 83 | # define NDNBOOST_CATCH_END } |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 84 | #endif |
| 85 | |
| 86 | |
| 87 | #endif |