Error types

The following types form a taxonomy of all the possible errors that BLACK can return to the user. These types are not thrown as exceptions, but returned as the error component of a std::expected object. This ensures they are always handled explicitly.

struct error

(Non-polymorphic) base class for all the following error classes.

Subclassed by black::support::io_error, black::support::syntax_error

Public Functions

template<typename ...Args>
inline error(const char *format, Args const&... args)
Parameters:
  • format – A format string (see std::format) for the error message.

  • args – The format string arguments.

Public Members

std::string message

The error message.

struct syntax_error : public black::support::error

A syntax error occurred in any input file read by BLACK.

Public Functions

template<typename ...Args>
inline syntax_error(std::optional<std::string> filename, size_t line, size_t column, const char *format, Args const&... args)
Parameters:
  • filename – The filename (see filename below).

  • line – The error line.

  • column – The error column.

  • format – A format string (see std::format) for the error message.

  • args – The format string arguments.

Public Members

std::optional<std::string> filename

The name of the file where the syntax error occurred. If filename is std::nullopt, the error came from some source different from a file (e.g. the standard input stream).

size_t line = 0

The line where the syntax error occurred.

size_t column = 0

The column where the syntax error occurred.

struct io_error : public black::support::error

An error occurred while reading or writing from files or streams.

Public Types

enum operation

Kind of operation that caused the error.

Values:

enumerator opening

The operation was the opening of a file.

enumerator reading

The operation was a read from a file or stream.

enumerator writing

The operation was a write to a file or stream.

Public Functions

template<typename ...Args>
inline io_error(std::optional<std::string> filename, operation op, int err, const char *format, Args const&... args)
Parameters:
  • filename – The filename (see filename below).

  • op – The kind of operation that caused the error.

  • err – The value of the errno variable describing the error.

  • format – A format string (see std::format) for the error message.

  • args – The format string arguments.

Public Members

std::optional<std::string> filename

The name of the file on which the error occurred. If filename is std::nullopt, the error came from some source. different from a file (e.g. the standard input stream).

operation op

The kind of operation that caused the error.

int err

The value of the errno variable describing the error.