Skip to content

exception_handling

Dmitry Koplyarov edited this page May 17, 2016 · 10 revisions

Back to reference

A policy that defines how the exceptions are handled.

namespace exception_handling
{
	struct none;
	struct print_to_stderr;
}

Table of contents

Supplied policies

none

Does not catch anything. This may cause exceptions from one handler to prevent other from being invoked.
Thus, it is strongly recommended to use a policy that catches and logs the exceptions.
You may either use the print_to_stderr policy or implement your own based on the log system you use.

The only reason this policy is the default one is that it does not produce any unwanted output.

print_to_stderr

A very basic logging exception policy. Prints the exception message to the stderr using fprintf.
Much safer than none, but cannot be integrated into you log system and catches std::exceptions only.

How to implement your own policy

struct my_exception_handling
{
	using tag = wigwag::exception_handling::tag<wigwag::api_version<2, 0>>;

	template < typename Func_, typename... Args_ >
	void handle_exceptions(Func_&& func, Args_&&... args) const;
};

Required nested types

tag

using tag = wigwag::exception_handling::tag<wigwag::api_version<2, 0>>;

The policy tag. Must be a type alias for wigwag::exception_handling::tag<wigwag::api_version<2, 0>>.

Required methods

handle_std_exceptions

template < typename Func_, typename... Args_ >
void handle_exceptions(Func_&& func, Args_&&... args) const;

This method should forward args... to the func functor object and handle any exceptions that may be thrown from func.

Arguments:

  • func - the function to be invoked
  • args... - the function arguments that you should forward to func functor object

Clone this wiki locally