OpenVPN 3 Core Library
Loading...
Searching...
No Matches
error.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_APPLECRYPTO_CF_ERROR_H
13#define OPENVPN_APPLECRYPTO_CF_ERROR_H
14
15#include <string>
16
17#include <CoreFoundation/CFBase.h>
18
20
21// An exception object that encapsulates Apple Core Foundation errors.
22
23namespace openvpn {
24
25// string exception class
26class CFException : public std::exception
27{
28 public:
29 explicit CFException(const std::string &text)
30 {
31 errtxt = text;
32 }
33
34 CFException(const std::string &text, const OSStatus status)
35 {
36 set_errtxt(text, status);
37 }
38
39 const char *what() const noexcept override
40 {
41 return errtxt.c_str();
42 }
43 std::string what_str() const
44 {
45 return errtxt;
46 }
47
48 virtual ~CFException() noexcept = default;
49
50 private:
51 void set_errtxt(const std::string &text, const OSStatus status)
52 {
53 std::ostringstream s;
54 s << text << ": OSX Error code=" << status;
55 errtxt = s.str();
56 }
57
58 std::string errtxt;
59};
60
61} // namespace openvpn
62
63#endif // OPENVPN_APPLECRYPTO_CF_ERROR_H
virtual ~CFException() noexcept=default
void set_errtxt(const std::string &text, const OSStatus status)
Definition error.hpp:51
CFException(const std::string &text, const OSStatus status)
Definition error.hpp:34
const char * what() const noexcept override
Definition error.hpp:39
CFException(const std::string &text)
Definition error.hpp:29
std::string errtxt
Definition error.hpp:58
std::string what_str() const
Definition error.hpp:43