File: exceptions.cpp

package info (click to toggle)
securefs 0.11.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,684 kB
  • sloc: cpp: 11,757; python: 486; sh: 11; makefile: 7
file content (69 lines) | stat: -rw-r--r-- 1,780 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "exceptions.h"
#include "logger.h"
#include "platform.h"

securefs::ExceptionBase::ExceptionBase() = default;

securefs::ExceptionBase::~ExceptionBase() = default;

void ::securefs::throwVFSException(int errc) { throw VFSException(errc); }

void ::securefs::throwInvalidArgumentException(const char* why)
{
    throw InvalidArgumentException(why);
}

void ::securefs::throwInvalidArgumentException(std::string why)
{
    throw InvalidArgumentException(std::move(why));
}

securefs::VFSException::~VFSException() = default;

securefs::POSIXException::~POSIXException() = default;

securefs::InvalidArgumentException::~InvalidArgumentException() = default;

[[noreturn]] void securefs::throwFileTypeInconsistencyException()
{
    throw ::securefs::FileTypeInconsistencyException();
}

[[noreturn]] void securefs::throwPOSIXExceptionDoNotUseDirectly(int err, std::string msg)
{
    throw POSIXException(err, std::move(msg));
}

[[noreturn]] void securefs::throw_runtime_error(const char* msg) { throw std::runtime_error(msg); }

[[noreturn]] void securefs::throw_runtime_error(const std::string& msg)
{
    throw std::runtime_error(msg);
}

std::string securefs::VFSException::message() const
{
    return securefs::OSService::stringify_system_error(m_errno);
}

std::string securefs::POSIXException::message() const
{
    return strprintf(
        "%s (%s)", securefs::OSService::stringify_system_error(m_errno).c_str(), m_msg.c_str());
}

const char* ::securefs::ExceptionBase::what() const noexcept
{
    if (m_cached_msg.empty())
    {
        try
        {
            message().swap(m_cached_msg);
        }
        catch (...)
        {
            return "An exception occurred while formatting exception message";
        }
    }
    return m_cached_msg.c_str();
}