Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ExceptionUtils.h File Reference

Utility functions for exception handling. More...

#include "arccore/base/BaseTypes.h"
#include "arccore/common/CommonGlobal.h"
#include <functional>
Include dependency graph for ExceptionUtils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  Arcane
 -- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --

Functions

Int32 Arcane::ExceptionUtils::print (ITraceMng *tm, bool is_no_continue=true)
 Prints a message for an unknown exception.
Int32 Arcane::ExceptionUtils::print (const std::exception &ex, ITraceMng *tm, bool is_no_continue=true)
 Prints a message for the standard exception ex.
Int32 Arcane::ExceptionUtils::print (const Exception &ex, ITraceMng *tm, bool is_no_continue=true)
 Prints a message for the standard exception ex.
Int32 Arcane::ExceptionUtils::callWithTryCatch (std::function< void()> function, ITraceMng *tm=nullptr)
 Calls a function while catching and displaying exceptions.
void Arcane::ExceptionUtils::callAndTerminateIfThrow (std::function< void()> function, ITraceMng *tm=nullptr)
 Calls a function and terminates the program if an exception occurs.

Detailed Description

Utility functions for exception handling.

Definition in file ExceptionUtils.h.

Function Documentation

◆ callAndTerminateIfThrow()

void Arcane::ExceptionUtils::callAndTerminateIfThrow ( std::function< void()> function,
ITraceMng * tm = nullptr )

Calls a function and terminates the program if an exception occurs.

Calls the function function via callWithTryCatch() and calls std::terminate() in case of an exception.

Definition at line 130 of file ExceptionUtils.cc.

◆ callWithTryCatch()

Int32 Arcane::ExceptionUtils::callWithTryCatch ( std::function< void()> function,
ITraceMng * tm = nullptr )

Calls a function while catching and displaying exceptions.

Executes the function function and catches any exceptions. In case of an exception, the print() function is called to display a message, and the return code is that of the print() function.

Usage:

callWithTryCatch([&]() { std::cout << "Hello\n"});
Returns
0 if no exception is thrown, and a positive value otherwise.

Definition at line 109 of file ExceptionUtils.cc.

◆ print() [1/3]

Int32 Arcane::ExceptionUtils::print ( const Exception & ex,
ITraceMng * tm,
bool is_no_continue = true )

Prints a message for the standard exception ex.

If tm is not null, it will be used for printing. If is_no_continue is true, it displays a message indicating that execution cannot continue.

Return values
3

Definition at line 90 of file ExceptionUtils.cc.

References Arcane::ITraceMng::error(), and Arcane::Exception::isCollective().

◆ print() [2/3]

Int32 Arcane::ExceptionUtils::print ( const std::exception & ex,
ITraceMng * tm,
bool is_no_continue = true )

Prints a message for the standard exception ex.

If trace_mng is not null, it will be used for printing. If is_no_continue is true, it displays a message indicating that execution cannot continue.

Return values
2

Definition at line 72 of file ExceptionUtils.cc.

References Arcane::ITraceMng::error().

◆ print() [3/3]

Int32 Arcane::ExceptionUtils::print ( ITraceMng * tm,
bool is_no_continue = true )

Prints a message for an unknown exception.

This function is used for catch(...) expressions.

If trace_mng is not null, it will be used for printing. If is_no_continue is true, it displays a message indicating that execution cannot continue.

Return values
1

Definition at line 55 of file ExceptionUtils.cc.

References Arcane::ITraceMng::error().