E-MailRelay

gexception.cpp
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gexception.cpp
19///
20
21#include "gdef.h"
22#include "gexception.h"
23#include "gstr.h"
24
25 G::Exception::Exception( std::initializer_list<std::string_view> args ) :
26 std::runtime_error(join(args))
27{
28}
29
30 G::Exception::Exception( std::string_view what ) :
31 Exception{what}
32{
33}
34
35 G::Exception::Exception( std::string_view what , std::string_view more ) :
36 Exception{what,more}
37{
38}
39
40 G::Exception::Exception( std::string_view what , std::string_view more1 , std::string_view more2 ) :
41 Exception{what,more1,more2}
42{
43}
44
45 G::Exception::Exception( std::string_view what , std::string_view more1 , std::string_view more2 ,
46 std::string_view more3 ) :
47 Exception{what,more1,more2,more3}
48{
49}
50
51 G::Exception::Exception( std::string_view what , std::string_view more1 , std::string_view more2 ,
52 std::string_view more3 , std::string_view more4 ) :
53 Exception{what,more1,more2,more3,more4}
54{
55}
56
57std::string G::Exception::join( std::initializer_list<std::string_view> args )
58{
59 std::string result ;
60 for( auto arg : args )
61 result.append(": ",result.empty()||arg.empty()?0U:2U).append(arg.data(),arg.size()) ;
62 return result ;
63}
64
G::Exception
A general-purpose exception class derived from std::exception and containing an error message.
Definition: gexception.h:64
G::Exception::Exception
Exception(std::initializer_list< std::string_view >)
Constructor.
Definition: gexception.cpp:25
gexception.h
gstr.h
std
STL namespace.