KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ki_error.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef KI_ERROR_H_
21#define KI_ERROR_H_
22
23#include <chrono>
24#include <fmt/format.h>
25
26#include <kicommon.h>
27#include <wx/string.h>
29
30class IO_ERROR;
31
38{
39public:
42 m_timestamp( std::chrono::system_clock::now() )
43 {}
44
45 explicit KI_ERROR( SEVERITY aSeverity, const wxString& aTitle = wxEmptyString ) :
46 m_title( aTitle ),
47 m_severity( aSeverity ),
48 m_timestamp( std::chrono::system_clock::now() )
49 {}
50
51 const wxString& GetTitle() const { return m_title; }
52 const wxString& GetDescription() const { return m_description; }
53 const wxString& GetDebugText() const { return m_debugText; }
54 SEVERITY GetSeverity() const { return m_severity; }
55
56 std::chrono::system_clock::time_point GetTimestamp() const { return m_timestamp; }
57
58 KI_ERROR& SetTitle( const wxString& aTitle )
59 {
60 m_title = aTitle;
61 return *this;
62 }
63
64 KI_ERROR& SetDescription( const wxString& aDescription )
65 {
66 m_description = aDescription;
67 return *this;
68 }
69
70 KI_ERROR& SetDebugText( const wxString& aDebugText )
71 {
72 m_debugText = aDebugText;
73 return *this;
74 }
75
77 {
78 m_severity = aSeverity;
79 return *this;
80 }
81
82 bool HasTitle() const { return !m_title.empty(); }
83 bool HasDescription() const { return !m_description.empty(); }
84 bool HasDebugText() const { return !m_debugText.empty(); }
85
86 wxString AsString() const;
87
88private:
89 wxString m_title;
90 wxString m_description;
91 wxString m_debugText;
93
94 std::chrono::system_clock::time_point m_timestamp;
95};
96
97
98// Provides {fmt} formatting
99auto format_as( const KI_ERROR& aError );
100
101#endif // KI_ERROR_H_
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Holds a structured error message.
Definition ki_error.h:38
const wxString & GetTitle() const
Definition ki_error.h:51
SEVERITY GetSeverity() const
Definition ki_error.h:54
wxString m_description
Definition ki_error.h:90
KI_ERROR & SetDebugText(const wxString &aDebugText)
Definition ki_error.h:70
std::chrono::system_clock::time_point GetTimestamp() const
Definition ki_error.h:56
wxString m_debugText
Definition ki_error.h:91
bool HasTitle() const
Definition ki_error.h:82
const wxString & GetDescription() const
Definition ki_error.h:52
wxString m_title
Definition ki_error.h:89
bool HasDescription() const
Definition ki_error.h:83
KI_ERROR & SetDescription(const wxString &aDescription)
Definition ki_error.h:64
std::chrono::system_clock::time_point m_timestamp
Definition ki_error.h:94
KI_ERROR & SetSeverity(SEVERITY aSeverity)
Definition ki_error.h:76
KI_ERROR()
Definition ki_error.h:40
SEVERITY m_severity
Definition ki_error.h:92
KI_ERROR & SetTitle(const wxString &aTitle)
Definition ki_error.h:58
KI_ERROR(SEVERITY aSeverity, const wxString &aTitle=wxEmptyString)
Definition ki_error.h:45
bool HasDebugText() const
Definition ki_error.h:84
const wxString & GetDebugText() const
Definition ki_error.h:53
auto format_as(const KI_ERROR &aError)
Definition ki_error.cpp:54
#define KICOMMON_API
Definition kicommon.h:27
STL namespace.
SEVERITY
@ RPT_SEVERITY_UNDEFINED