2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSLIB_DETAILS_THROW_EXCEPTION_H
32 #define CDSLIB_DETAILS_THROW_EXCEPTION_H
34 #include <cds/details/defs.h>
35 #if !defined( CDS_EXCEPTION_ENABLED ) && !defined( CDS_USER_DEFINED_THROW_HANDLER )
41 #if !defined( CDS_USER_DEFINED_THROW_EXCEPTION )
42 #if defined( CDS_EXCEPTION_ENABLED )
43 /// Function to throw an exception
45 If you compile your code with exception enabled, \p %throw_exception() function
46 throws the \p exception.
48 If exception is disabled, \p %throw_exception() prints an exception message to
49 standard output and call \p abort().
51 You can supply your own \p %cds::throw_exception() function;
52 for that you should specify \p -DCDS_USER_DEFINED_THROW_EXCEPTION
53 in compiler command line.
55 @note \p %throw_exception() never returns. If the user-defined \p %throw_exception() returns,
56 the behavior is undefined.
59 CDS_NORETURN static inline void throw_exception(
60 E&& exception, ///< Exception to throw
61 char const* file, ///< Source filename
62 int line ///< File line
72 CDS_NORETURN static inline void throw_exception( E&& exception, char const* file, int line )
74 printf( "file %s, line %d: %s\n", file, line, exception.what());
79 // User-provided cds::throw_exception()
82 #define CDS_THROW_EXCEPTION( exception ) ::cds::throw_exception( exception, __FILE__, __LINE__ )
87 #endif // #ifndef CDSLIB_DETAILS_THROW_EXCEPTION_H