Arcane  v4.1.1.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
ExceptionUtils.h
Aller à la documentation de ce fichier.
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ExceptionUtils.h (C) 2000-2025 */
9/* */
10/* Fonctions utilitaires pour la gestion des exceptions. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_COMMON_EXCEPTIONUTILS_H
13#define ARCCORE_COMMON_EXCEPTIONUTILS_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18#include "arccore/common/CommonGlobal.h"
19
20#include <functional>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::ExceptionUtils
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30/*!
31 * \brief Imprime un message pour une exception inconnue.
32 *
33 * Cette fonction sert pour les expressions du type `catch(...)`.
34 *
35 * Si \a trace_mng est non nul, il sera utilisé pour l'impression.
36 * Si \a is_no_continue est vrai, affiche un message indiquant qu'on ne peut
37 * plus continuer l'exécution.
38 *
39 * \retval 1
40 */
41extern "C++" ARCCORE_COMMON_EXPORT Int32
42print(ITraceMng* tm, bool is_no_continue = true);
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
46/*!
47 * \brief Imprime un message pour l'exception standard \a ex.
48 *
49 * Si \a trace_mng est non nul, il sera utilisé pour l'impression.
50 * Si \a is_no_continue est vrai, affiche un message indiquant qu'on ne peut
51 * plus continuer l'exécution.
52 *
53 * \retval 2
54 */
55extern "C++" ARCCORE_COMMON_EXPORT Int32
56print(const std::exception& ex, ITraceMng* tm, bool is_no_continue = true);
57
58/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60/*!
61 * \brief Imprime un message pour l'exception standard \a ex.
62 *
63 * Si \a tm est non nul, il sera utilisé pour l'impression.
64 * Si \a is_no_continue est vrai, affiche un message indiquant qu'on ne peut
65 * plus continuer l'exécution.
66 *
67 * \retval 3
68 */
69extern "C++" ARCCORE_COMMON_EXPORT Int32
70print(const Exception& ex, ITraceMng* tm, bool is_no_continue = true);
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74/*!
75 * \brief Appelle une fonction en récupérant et affichant les exceptions.
76 *
77 * Applique la fonction \a function et récupère les éventuelles exceptions.
78 * En cas d'exception, la fonction print() est appelée pour afficher un
79 * message et le code de retour est celui de la fonction print().
80 *
81 * Usage:
82 *
83 * \code
84 * callWithTryCatch([&]() { std::cout << "Hello\n"});
85 * \endcode
86 *
87 * \return 0 si aucune exception n'est lancée et une valeur positive dans
88 * le cas contraire.
89 */
90extern "C++" ARCCORE_COMMON_EXPORT Int32
91callWithTryCatch(std::function<void()> function, ITraceMng* tm = nullptr);
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95/*!
96 * \brief Appelle une fonction et termine le programme en cas d'exception.
97 *
98 * Appelle la fonction \a function via callWithTryCatch() et appelle
99 * std::terminate() en cas d'exception.
100 */
101extern "C++" ARCCORE_COMMON_EXPORT void
102callAndTerminateIfThrow(std::function<void()> function, ITraceMng* tm = nullptr);
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
107} // namespace Arcane::ExceptionUtils
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
112#endif
Déclarations des types de la composante 'base' de Arccore.
Int32 print(ITraceMng *tm, bool is_no_continue=true)
Imprime un message pour une exception inconnue.
void callAndTerminateIfThrow(std::function< void()> function, ITraceMng *tm=nullptr)
Appelle une fonction et termine le programme en cas d'exception.
Int32 callWithTryCatch(std::function< void()> function, ITraceMng *tm=nullptr)
Appelle une fonction en récupérant et affichant les exceptions.
std::int32_t Int32
Type entier signé sur 32 bits.