Template Function navtk::log_or_throw

Function Documentation

template<typename Exc = DefaultLogOrThrowException, spdlog::level::level_enum Level = DEFAULT_LOG_OR_THROW_LEVEL, typename ...FormatArgs>
void navtk::log_or_throw(ErrorMode mode, spdlog::format_string_t<FormatArgs...> fmt, FormatArgs&&... args)

Write a log message or throw an error, depending on the value of the given navtk::ErrorMode.

Template Parameters
  • Exc – The exception type. When the mode is ErrorMode::DIE, an instance of this exception will be thrown, initialized with a string error message as its constructor parameter.

  • Level – The log level to use when logging the error message.

  • FormatArgs – Type parameters for the args argument. The first of these should be implicitly convertible to std::string. Others can be any type.

Parameters
  • mode – Which behavior(s) to enable. ErrorMode::LOG emits a log message only, ErrorMode::DIE logs and throws an exception. This parameter can be omitted, in which case the current value of get_global_error_mode() will be used.

  • fmt – A fmt-style format string ("foo: {}"), as you’d pass to fmt::format. If you need to dynamically generate a format string, wrap it in fmt::runtime to avoid the compiler error, but as a general practice you should avoid this. If you just want to log a dynamic string, use log_or_throw("{}", your_dynamic_string); instead.

  • args – Arguments needed by the format string, as you’d pass to fmt::format. https://github.com/fmtlib/fmt for details.

Throws

An – instance of Exc if mode is ErrorMode::DIE.