Reference documentation for deal.II version GIT relicensing-487-ge9eb5ab491 2024-04-25 07:20:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
utilities.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15
16#ifndef dealii_sundials_utilities_h
17#define dealii_sundials_utilities_h
18
19#include <deal.II/base/config.h>
20
21#ifdef DEAL_II_WITH_SUNDIALS
22# include <exception>
23
24
26
27namespace SUNDIALS
28{
29 namespace Utilities
30 {
43 template <typename F, typename... Args>
44 int
46 std::exception_ptr &eptr,
47 Args &&...args)
48 {
49 // See whether there is already something in the exception pointer
50 // variable. This can only happen if we had previously had
51 // a recoverable exception, and the underlying library actually
52 // did recover successfully. In that case, we can abandon the
53 // exception previously thrown. If eptr contains anything other,
54 // then we really don't know how that could have happened, and
55 // should probably bail out:
56 if (eptr)
57 {
58 try
59 {
60 std::rethrow_exception(eptr);
61 }
62 catch (const RecoverableUserCallbackError &)
63 {
64 // ok, ignore, but reset the pointer
65 eptr = nullptr;
66 }
67 catch (...)
68 {
69 // uh oh:
71 }
72 }
73
74 // Call the function and if that succeeds, return zero:
75 try
76 {
77 f(std::forward<Args>(args)...);
78 eptr = nullptr;
79 return 0;
80 }
81 // If the call failed with a recoverable error, then
82 // ignore the exception for now (but store a pointer to it)
83 // and return a positive return value (+1). If the underlying
84 // implementation manages to recover
85 catch (const RecoverableUserCallbackError &)
86 {
87 eptr = std::current_exception();
88 return 1;
89 }
90 // For any other exception, capture the exception and
91 // return -1:
92 catch (const std::exception &)
93 {
94 eptr = std::current_exception();
95 return -1;
96 }
97 }
98 } // namespace Utilities
99} // namespace SUNDIALS
100
102
103#endif // DEAL_II_WITH_SUNDIALS
104
105#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & RecoverableUserCallbackError()
#define AssertThrow(cond, exc)
int call_and_possibly_capture_exception(const F &f, std::exception_ptr &eptr, Args &&...args)
Definition utilities.h:45