Cppgres
Build Postgres extensions in C++
Loading...
Searching...
No Matches
guard.hpp File Reference
#include <setjmp.h>
#include <exception>
#include <iostream>
#include <utility>
#include "error.hpp"
#include "exception.hpp"
#include "utils/function_traits.hpp"

Go to the source code of this file.

Classes

struct  cppgres::ffi_guard< Func >
 
struct  cppgres::scope_fail< Func >
 Scope guard that runs the callable only when the scope is left via an exception. More...
 
struct  cppgres::scope_exit< Func >
 Scope guard that always runs the callable on scope exit. More...
 
struct  cppgres::exception_guard< Func >
 Wraps a C++ function to catch exceptions and report them as Postgres errors. More...
 

Functions

template<typename Func >
void cppgres::ffi_guard_noexcept (Func f, const char *warning_message) noexcept
 Runs a callable under cppgres::ffi_guard, degrading any failure to a warning.
 
template<typename Func >
 cppgres::scope_fail (Func, const char *) -> scope_fail< Func >
 
template<typename Func >
 cppgres::scope_exit (Func, const char *) -> scope_exit< Func >
 

Function Documentation

◆ ffi_guard_noexcept()

template<typename Func >
void cppgres::ffi_guard_noexcept ( Func  f,
const char *  warning_message 
)
noexcept

Runs a callable under cppgres::ffi_guard, degrading any failure to a warning.

Catches every exception — including Postgres errors surfaced as cppgres::pg_exception — and reports the given message with elog(WARNING) instead of propagating. Intended for destructors and other cleanup paths where failure must degrade to a WARNING instead of propagating.

Parameters
fcallable to run
warning_messagemessage to report at WARNING level if the callable fails