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
25#include <kicommon.h>
26#include <wx/string.h>
28
29class IO_ERROR;
30
37{
38public:
41 m_timestamp( std::chrono::system_clock::now() )
42 {}
43
44 explicit KI_ERROR( SEVERITY aSeverity, const wxString& aTitle = wxEmptyString ) :
45 m_title( aTitle ),
46 m_severity( aSeverity ),
47 m_timestamp( std::chrono::system_clock::now() )
48 {}
49
50 const wxString& GetTitle() const { return m_title; }
51 const wxString& GetDescription() const { return m_description; }
52 const wxString& GetDebugText() const { return m_debugText; }
53 SEVERITY GetSeverity() const { return m_severity; }
54
55 std::chrono::system_clock::time_point GetTimestamp() const { return m_timestamp; }
56
57 KI_ERROR& SetTitle( const wxString& aTitle )
58 {
59 m_title = aTitle;
60 return *this;
61 }
62
63 KI_ERROR& SetDescription( const wxString& aDescription )
64 {
65 m_description = aDescription;
66 return *this;
67 }
68
69 KI_ERROR& SetDebugText( const wxString& aDebugText )
70 {
71 m_debugText = aDebugText;
72 return *this;
73 }
74
76 {
77 m_severity = aSeverity;
78 return *this;
79 }
80
81 bool HasTitle() const { return !m_title.empty(); }
82 bool HasDescription() const { return !m_description.empty(); }
83 bool HasDebugText() const { return !m_debugText.empty(); }
84
85 wxString AsString() const;
86
87private:
88 wxString m_title;
89 wxString m_description;
90 wxString m_debugText;
92
93 std::chrono::system_clock::time_point m_timestamp;
94};
95
96
97// Provides {fmt} formatting
98auto format_as( const KI_ERROR& aError );
99
100#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:37
const wxString & GetTitle() const
Definition ki_error.h:50
SEVERITY GetSeverity() const
Definition ki_error.h:53
wxString m_description
Definition ki_error.h:89
KI_ERROR & SetDebugText(const wxString &aDebugText)
Definition ki_error.h:69
std::chrono::system_clock::time_point GetTimestamp() const
Definition ki_error.h:55
wxString m_debugText
Definition ki_error.h:90
bool HasTitle() const
Definition ki_error.h:81
const wxString & GetDescription() const
Definition ki_error.h:51
wxString m_title
Definition ki_error.h:88
bool HasDescription() const
Definition ki_error.h:82
KI_ERROR & SetDescription(const wxString &aDescription)
Definition ki_error.h:63
std::chrono::system_clock::time_point m_timestamp
Definition ki_error.h:93
KI_ERROR & SetSeverity(SEVERITY aSeverity)
Definition ki_error.h:75
KI_ERROR()
Definition ki_error.h:39
SEVERITY m_severity
Definition ki_error.h:91
KI_ERROR & SetTitle(const wxString &aTitle)
Definition ki_error.h:57
KI_ERROR(SEVERITY aSeverity, const wxString &aTitle=wxEmptyString)
Definition ki_error.h:44
bool HasDebugText() const
Definition ki_error.h:83
const wxString & GetDebugText() const
Definition ki_error.h:52
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