lib45d
45Drives C++ Library Development Documentation
Exceptions.hpp
1 // -*- C++ -*-
2 /*
3  * Copyright (C) 2021 Joshua Boudreau <jboudreau@45drives.com>
4  *
5  * This file is part of lib45d.
6  *
7  * lib45d is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * lib45d is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with lib45d. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
21 #pragma once
22 
23 #include <string>
24 
25 namespace ffd {
30  class Exception {
31  public:
38  Exception(const std::string &what, int err = 0) noexcept : what_(what), errno_(err) {}
44  const char *what(void) const noexcept {
45  return what_.c_str();
46  }
52  int get_errno(void) const noexcept {
53  return errno_;
54  }
55  private:
56  std::string what_;
57  int errno_;
58  };
59 
64  class ByteParseException : public Exception {
65  private:
66  std::string what_;
67  public:
68  ByteParseException(const std::string &what) noexcept : Exception(what) {}
69  };
70 
75  class QuotaParseException : public Exception {
76  private:
77  std::string what_;
78  public:
79  QuotaParseException(const std::string &what) noexcept : Exception(what) {}
80  };
81 } // namespace ffd
ffd::ByteParseException
Throw this exception when Bytes::set() fails to parse string.
Definition: Exceptions.hpp:64
ffd::Exception::errno_
int errno_
Optionally save errno if applicable.
Definition: Exceptions.hpp:57
ffd
45Drives namespace
Definition: Bytes.hpp:27
ffd::Exception::what_
std::string what_
String containing explanation message.
Definition: Exceptions.hpp:56
ffd::QuotaParseException::what_
std::string what_
String containing explanation message.
Definition: Exceptions.hpp:77
ffd::Exception::what
const char * what(void) const noexcept
Return string containing explanation message.
Definition: Exceptions.hpp:44
ffd::Exception::get_errno
int get_errno(void) const noexcept
Get the errno relating to the error, 0 if not set.
Definition: Exceptions.hpp:52
ffd::Exception::Exception
Exception(const std::string &what, int err=0) noexcept
Construct a new Exception object.
Definition: Exceptions.hpp:38
ffd::Exception
Exceptions thrown by this library.
Definition: Exceptions.hpp:30
ffd::QuotaParseException
Throw this exception when Quota::parse_fraction() fails to parse string.
Definition: Exceptions.hpp:75
ffd::ByteParseException::what_
std::string what_
String containing explanation message.
Definition: Exceptions.hpp:66