CGRA-ME
Classes | Functions
Exception.h File Reference
#include <cstdlib>
#include <exception>
#include <sstream>
#include <stdexcept>
#include <string>

Go to the source code of this file.

Classes

struct  cgrame_error
 
struct  cgrame_mapper_error
 
struct  cgrame_visual_error
 
struct  cgrame_adl_error
 
struct  cgrame_model_error
 

Functions

template<typename EXCEPTION , typename FUNC >
void make_and_throw (FUNC func)
 
template<typename T , typename FUNC >
auto make_from_stream (FUNC func)
 
template<typename F >
std::string string_from_stream (F &&f)
 
void tryToSafelyPrintExceptionInfo (std::exception_ptr eptr, std::ostream &os, const char *action_name) noexcept
 
void printExceptionToOutAndErr (std::exception_ptr eptr, const char *line_prefix, const char *message)
 

Function Documentation

◆ make_and_throw()

template<typename EXCEPTION , typename FUNC >
void make_and_throw ( FUNC  func)

A convenience function for throwing exceptions. Lets you do this:

int x = computation() if (x != 0) { make_and_throw([&](auto&& s) { s << "x was not zero! it was " << x; }); }

Definition at line 66 of file Exception.h.

◆ make_from_stream()

template<typename T , typename FUNC >
auto make_from_stream ( FUNC  func)

A convenience function for constructing things that expect strings, but when you would like to use a stream. Such as throwing exceptions. Lets you do this:

int x = computation() if (x != 0) { throw make_from_stream<std::logic_error>([&](auto&& s) { s << "x was not zero! it was " << x; }); }

Definition at line 85 of file Exception.h.

◆ printExceptionToOutAndErr()

void printExceptionToOutAndErr ( std::exception_ptr  eptr,
const char *  line_prefix,
const char *  message 
)
inline

Prints a message to both stderr and stdout derived from eptr Intended to be used when an exception is going to be ignored. Handles std::nested_exception properly, and will print messages from the nested exceptions.

Definition at line 134 of file Exception.h.

◆ string_from_stream()

template<typename F >
std::string string_from_stream ( F &&  f)

Runs the given functor on a stringstream, and retuns the string

Definition at line 95 of file Exception.h.

◆ tryToSafelyPrintExceptionInfo()

void tryToSafelyPrintExceptionInfo ( std::exception_ptr  eptr,
std::ostream &  os,
const char *  action_name 
)
inlinenoexcept

Print the given eptr to os, reasonably safely Intended for use in a destructor or something, when an throw exception cannot be tolerated. Does not handle std::nested_exception specially. Will not allocate, except if os does

Definition at line 107 of file Exception.h.