deal.II version GIT relicensing-2947-g2b65dfb0bb 2025-03-26 20:50:00+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
22
23
24#ifdef DEAL_II_WITH_SUNDIALS
25# include <exception>
26
27
29
30namespace SUNDIALS
31{
32 namespace Utilities
33 {
46 template <typename F, typename... Args>
47 int
49 std::exception_ptr &eptr,
50 Args &&...args)
51 {
52 // See whether there is already something in the exception pointer
53 // variable. This can only happen if we had previously had
54 // a recoverable exception, and the underlying library actually
55 // did recover successfully. In that case, we can abandon the
56 // exception previously thrown. If eptr contains anything other,
57 // then we really don't know how that could have happened, and
58 // should probably bail out:
59 if (eptr)
60 {
61 try
62 {
63 std::rethrow_exception(eptr);
64 }
65 catch (const RecoverableUserCallbackError &)
66 {
67 // ok, ignore, but reset the pointer
68 eptr = nullptr;
69 }
70 catch (...)
71 {
72 // uh oh:
74 }
75 }
76
77 // Call the function and if that succeeds, return zero:
78 try
79 {
80 f(std::forward<Args>(args)...);
81 eptr = nullptr;
82 return 0;
83 }
84 // If the call failed with a recoverable error, then
85 // ignore the exception for now (but store a pointer to it)
86 // and return a positive return value (+1). If the underlying
87 // implementation manages to recover
88 catch (const RecoverableUserCallbackError &)
89 {
90 eptr = std::current_exception();
91 return 1;
92 }
93 // For any other exception, capture the exception and
94 // return -1:
95 catch (const std::exception &)
96 {
97 eptr = std::current_exception();
98 return -1;
99 }
100 }
101 } // namespace Utilities
102} // namespace SUNDIALS
103
105
106#endif // DEAL_II_WITH_SUNDIALS
107
108#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:40
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:41
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:48