This week, I’ll present you a small device I wrote to handle basic errors, the most compact and generic I could think of. If you want to skip th

One of the simplest error handlers ever written

submited by
Style Pass
2022-01-12 23:30:08

This week, I’ll present you a small device I wrote to handle basic errors, the most compact and generic I could think of.

If you want to skip the article and go directly to the source, here is the Github repo: SenuaChloe/SimplestErrorHandler (github.com)

So that’ll be the basic criteria I’ll be relying on to design the error handler (we may add a few specifications along the way).

To make it very light and simple, all the code will be in a single header file (it’s simpler to include a header into your project than a lib). But since there will probably be auxiliary functions (that won’t be part of the interface), we need a way to hide them.

That’s why we will put all the code in a full-static class1. There will be private static member functions (for this internal functions), public static member functions (the interface), and possibly types and such.

To have a fully customizable error message, we need a variable number of arguments (and thus some variadic templates). We will recurse over the arguments2, streaming each of them, starting with head, into a stream.

Leave a Comment