Veethree D7 SDK
Loading...
Searching...
No Matches
vsdk::io::libio_error Class Reference

Detailed Description

The libio_error class.

A std::system_error specialisation that allows to take a vsdk::io::io_module and vsdk::io::io_error values in the constructors. Also provides more information allowing to locate where the error happened (submodule:operation).

#include <libio_error.h>

Public Member Functions

 libio_error (io_module module, std::error_code ec, const std::string &message="", source_location loc=source_location::current())
 Class constructor.
 libio_error (io_module module, io_error ec, const std::string &message="", source_location loc=source_location::current())
 Class constructor.
 libio_error (io_module module, int ev, const std::error_category &ecat, const std::string &message="", source_location loc=source_location::current())
 Class constructor.
const char * what () const noexcept override
 Provide a string description for this error.
const module_value & module () const
 Module object based on io_module.
const source_location & location () const
 Exception location.

Detailed Description

The libio_error class.

A std::system_error specialisation that allows to take a vsdk::io::io_module and vsdk::io::io_error values in the constructors. Also provides more information allowing to locate where the error happened (submodule:operation).

Constructor & Destructor Documentation

◆ libio_error() [1/3]

vsdk::io::libio_error::libio_error ( io_module module,
std::error_code ec,
const std::string & message = "",
source_location loc = source_location::current() )
explicit

Class constructor.

Parameters
moduleThe io_module where the error happened.
ecA std::error_code value, see standard documentation for more information.
messageUser message.
locA source_location value, use it as a default parameter.
See also
make_io_error
io_module
io_error
source_location

Sample code:

void fn()
{
using namespace vsdk::io;
// or...
auto err = std::make_error_code(std::errc::io_error);
throw libio_error(io_module::pwm_out, err, "tried to enable pwm");
}
libio_error(io_module module, std::error_code ec, const std::string &message="", source_location loc=source_location::current())
Class constructor.
vsdk::io::libio_error interface, based on std::system_error
Any entities that belong to the IO library.
@ pwm_out
PWM Output.
Definition io_error_codes.h:22
std::error_code make_io_error(io_error ec)
Convenience function to be used when throwing std::system_error exceptions.
@ enable
enable operation failed
Definition io_error_codes.h:38

◆ libio_error() [2/3]

vsdk::io::libio_error::libio_error ( io_module module,
io_error ec,
const std::string & message = "",
source_location loc = source_location::current() )
explicit

Class constructor.

Parameters
moduleThe io_module where the error happened.
ecThe io_error describing the error.
messageUser message.
locA source_location value, use it as a default parameter.
See also
io_module
io_error
source_location

Sample code:

void fn()
{
using namespace vsdk::io;
throw libio_error(io_module::pwm_out, io_error::enable, "tried to enable pwm");
}

◆ libio_error() [3/3]

vsdk::io::libio_error::libio_error ( io_module module,
int ev,
const std::error_category & ecat,
const std::string & message = "",
source_location loc = source_location::current() )
explicit

Class constructor.

Parameters
moduleThe io_module where the error happened.
evGeneric error value.
ecatA category derived from std::error_category.
messageUser message.
locA source_location value, use it as a default parameter.
See also
io_category
std::system_category
source_location

Sample code:

#include <cerrno>
void fn()
{
using namespace vsdk::io;
throw libio_error(io_module::pwm_out, static_cast<io_error>(io_error::enable), io_category::category(), "tried to enable pwm");
// or...
throw libio_error(io_module::pwm_out, errno, std::system_category(), "tried to enable pwm");
}
static const io_category & category()
The io_category unique instance.
io_error
The io_error enum.
Definition io_error_codes.h:34

Member Function Documentation

◆ location()

const source_location & vsdk::io::libio_error::location ( ) const

Exception location.

Returns
Return a source_location object describing file, line and function where the exception was thrown.
See also
source_location

Sample code:

void fn()
{
using namespace vsdk;
using namespace vsdk::io;
try {
//...
} catch (const libio_error& e) {
utils::print("error: file {} function {} line {}\n", e.location().file_name(), e.location().function_name(), e.location().line());
utils::print("error: code {} description {}\n", e.code().value(), e.code().message());
utils::print("error: category {}\n", e.code().category().name());
}
}
The libio_error class.
Definition libio_error.h:103
const source_location & location() const
Exception location.
int line() const
The source file line.
std::string function_name() const
The source file function_name.
std::string file_name() const
The source file name.
Add include this file to your file so you have access to fmtlib header-only implementation.
void print(fmt::format_string< Args... > fmt, Args &&...args) noexcept
Exception-safe fmt::print wrapper.
Definition fmt_wrapper.h:26
Any entities that belong to the Veethree SDK libraries.
Definition can_adapter.h:12

◆ module()

const module_value & vsdk::io::libio_error::module ( ) const

Module object based on io_module.

Returns
Return this object's module_value instance based on the io_module provided in the constructor.
See also
module_value

Sample code:

void fn()
{
using namespace vsdk;
using namespace vsdk::io;
try {
//...
} catch (const libio_error& e) {
utils::print("error: name {} value {}\n", e.module().name(), e.module().value());
utils::print("error: code {} description {}\n", e.code().value(), e.code().message());
utils::print("error: category {}\n", e.code().category().name());
}
}
const module_value & module() const
Module object based on io_module.
io_module value() const
The io_module value.
const std::string & name() const
The io_module name.

◆ what()

const char * vsdk::io::libio_error::what ( ) const
overridenoexcept

Provide a string description for this error.

Returns
A string describing the error. Format is 'category:io_module:category string (value):user message'.

Sample code:

void fn()
{
try {
//...
} catch (const std::exception& e) {
std::cout << e.what() << '\n';
// example: system:digital-io:Input/output error (5):the message
}
}

The documentation for this class was generated from the following file: