OpenVPN 3 Core Library
Loading...
Searching...
No Matches
excode.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#ifndef OPENVPN_ERROR_EXCODE_H
13#define OPENVPN_ERROR_EXCODE_H
14
15#include <string>
16#include <exception>
17
19
20namespace openvpn {
21
22// Define an exception object that allows an Error::Type code to be thrown
23class ExceptionCode : public std::exception
24{
25 public:
26 ExceptionCode() = default;
28 : code_(code)
29 {
30 }
33 {
34 }
35
37 {
38 code_ = code;
39 }
40
41 void set_code(const Error::Type code, const bool fatal)
42 {
43 code_ = code;
44 fatal_ = fatal;
45 }
46
48 {
49 return code_;
50 }
51 bool fatal() const
52 {
53 return fatal_;
54 }
55
56 bool code_defined() const
57 {
58 return code_ != Error::SUCCESS;
59 }
60
62 bool is_tls_alert() const
63 {
65 }
66
67 virtual ~ExceptionCode() noexcept = default;
68
69 private:
70 Error::Type code_ = Error::SUCCESS;
71 bool fatal_ = false;
72};
73
75{
76 public:
77 ErrorCode(const Error::Type code, const bool fatal, const std::string &err)
78 : ExceptionCode(code, fatal), err_(err)
79 {
80 }
81
82 const char *what() const noexcept override
83 {
84 return err_.c_str();
85 }
86
87 virtual ~ErrorCode() noexcept = default;
88
89 private:
90 std::string err_;
91};
92
93} // namespace openvpn
94#endif
const char * what() const noexcept override
Definition excode.hpp:82
ErrorCode(const Error::Type code, const bool fatal, const std::string &err)
Definition excode.hpp:77
virtual ~ErrorCode() noexcept=default
bool is_tls_alert() const
Some errors may justify letting the underlying SSL library send out TLS alerts.
Definition excode.hpp:62
Error::Type code_
Definition excode.hpp:70
bool fatal() const
Definition excode.hpp:51
virtual ~ExceptionCode() noexcept=default
ExceptionCode(const Error::Type code, const bool fatal)
Definition excode.hpp:31
ExceptionCode(const Error::Type code)
Definition excode.hpp:27
Error::Type code() const
Definition excode.hpp:47
void set_code(const Error::Type code)
Definition excode.hpp:36
void set_code(const Error::Type code, const bool fatal)
Definition excode.hpp:41
bool code_defined() const
Definition excode.hpp:56