Reference documentation for deal.II version 9.5.0
\(\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// Copyright (C) 2023 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16
17#ifndef dealii_sundials_utilities_h
18#define dealii_sundials_utilities_h
19
20#include <deal.II/base/config.h>
21
22#ifdef DEAL_II_WITH_SUNDIALS
23# include <exception>
24
25
27
28namespace SUNDIALS
29{
30 namespace Utilities
31 {
44 template <typename F, typename... Args>
45 int
47 std::exception_ptr &eptr,
48 Args &&...args)
49 {
50 // See whether there is already something in the exception pointer
51 // variable. This can only happen if we had previously had
52 // a recoverable exception, and the underlying library actually
53 // did recover successfully. In that case, we can abandon the
54 // exception previously thrown. If eptr contains anything other,
55 // then we really don't know how that could have happened, and
56 // should probably bail out:
57 if (eptr)
58 {
59 try
60 {
61 std::rethrow_exception(eptr);
62 }
63 catch (const RecoverableUserCallbackError &)
64 {
65 // ok, ignore, but reset the pointer
66 eptr = nullptr;
67 }
68 catch (...)
69 {
70 // uh oh:
72 }
73 }
74
75 // Call the function and if that succeeds, return zero:
76 try
77 {
78 f(std::forward<Args>(args)...);
79 eptr = nullptr;
80 return 0;
81 }
82 // If the call failed with a recoverable error, then
83 // ignore the exception for now (but store a pointer to it)
84 // and return a positive return value (+1). If the underlying
85 // implementation manages to recover
86 catch (const RecoverableUserCallbackError &)
87 {
88 eptr = std::current_exception();
89 return 1;
90 }
91 // For any other exception, capture the exception and
92 // return -1:
93 catch (const std::exception &)
94 {
95 eptr = std::current_exception();
96 return -1;
97 }
98 }
99 } // namespace Utilities
100} // namespace SUNDIALS
101
103
104#endif // DEAL_II_WITH_SUNDIALS
105
106#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
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:46