LeechCraft Azoth 0.6.70-16373-g319c272718
Modular multiprotocol IM plugin for LeechCraft
Loading...
Searching...
No Matches
gpgexceptions.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <stdexcept>
12#include <variant>
13#include <optional>
14
15namespace LC
16{
17namespace Azoth
18{
19namespace GPGExceptions
20{
37 class General : public std::runtime_error
38 {
39 QString Context_;
40 int Code_ = -1;
41 QString Message_;
42 public:
48 General (const QString& context)
49 : std::runtime_error { context.toStdString () }
50 , Context_ { context }
51 {
52 }
53
61 General (const QString& context, int code, const QString& message)
62 : std::runtime_error
63 {
64 context.toStdString () + std::to_string (code) + ": " + message.toStdString ()
65 }
66 , Context_ { context }
67 , Code_ { code }
68 , Message_ { message }
69 {
70 }
71
78 General (int code, const QString& msg)
79 : General { "Azoth GPG error", code, msg }
80 {
81 }
82
87 const QString& GetContext () const
88 {
89 return Context_;
90 }
91
96 int GetCode () const
97 {
98 return Code_;
99 }
100
105 const QString& GetMessage () const
106 {
107 return Message_;
108 }
109 };
110
113 class NullPubkey : public General
114 {
115 public:
119 : General { "Azoth GPG: null pubkey" }
120 {
121 }
122 };
123
126 class Encryption : public General
127 {
128 public:
136 Encryption (int code, const QString& message)
137 : General { "Azoth GPG encryption error", code, message }
138 {
139 }
140 };
141
144 using AnyException_t = std::variant<Encryption, NullPubkey, General>;
145
148 using MaybeException_t = std::optional<AnyException_t>;
149}
150}
151}
Encryption(int code, const QString &message)
Constructs the error object using the error code and message.
const QString & GetMessage() const
Returns the human-readable error message.
General(int code, const QString &msg)
Constructs the error with the given code and error message.
const QString & GetContext() const
Returns the context of the error.
int GetCode() const
Returns the error code, if applicable.
General(const QString &context, int code, const QString &message)
Constructs the error with the given context, code and error message.
General(const QString &context)
Constructs the error with the given context description.
An error resulting from a null (or unset) public key.
NullPubkey()
Constructs the error object.
std::optional< AnyException_t > MaybeException_t
A type representing a possibility of a GPG-related error.
std::variant< Encryption, NullPubkey, General > AnyException_t
A sum type of all the possible GPG-related errors.