OTest2
A C++ testing framework
lib
exccatcherordinary.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2019 Ondrej Starek
3
*
4
* This file is part of OTest2.
5
*
6
* OTest2 is free software: you can redistribute it and/or modify it under
7
* the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License,
9
* or (at your option) any later version.
10
*
11
* OTest2 is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14
* License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#include <
exccatcherordinary.h
>
21
22
#include <exception>
23
#include <sstream>
24
#include <typeinfo>
25
26
#include <
exc.h
>
27
28
namespace
OTest2
{
29
30
ExcCatcherOrdinary::ExcCatcherOrdinary
() {
31
32
}
33
34
ExcCatcherOrdinary::~ExcCatcherOrdinary
() {
35
36
}
37
38
bool
ExcCatcherOrdinary::catchException
(
39
const
Context
& context_,
40
std::function<
void
(
const
Context
&)> ftor_,
41
std::string& message_) noexcept {
42
/* -- run the functor */
43
try
{
44
ftor_(context_);
45
}
46
catch
(
const
Exception
& exc_) {
47
std::ostringstream sos_;
48
sos_ <<
"unexpected exception: "
<< exc_.
reason
();
49
message_ = sos_.str();
50
return
true
;
51
}
52
catch
(
const
std::exception& exc_) {
53
std::ostringstream sos_;
54
sos_ <<
"unexpected exception: "
<< exc_.what();
55
message_ = sos_.str();
56
return
true
;
57
}
58
catch
(...) {
59
message_ =
"unexpected unknown exception"
;
60
return
true
;
61
}
62
63
return
false
;
64
}
65
66
}
/* namespace OTest2 */
OTest2::Exception::reason
virtual std::string reason() const =0
Get exception reason.
OTest2::ExcCatcherOrdinary::ExcCatcherOrdinary
ExcCatcherOrdinary()
Ctor.
Definition:
exccatcherordinary.cpp:30
OTest2::ExcCatcherOrdinary::~ExcCatcherOrdinary
virtual ~ExcCatcherOrdinary()
Dtor.
Definition:
exccatcherordinary.cpp:34
exc.h
OTest2
Definition:
assertbean.h:25
OTest2::Exception
Generic OTest2 exception.
Definition:
exc.h:31
OTest2::Context
OTest2 runtime context.
Definition:
context.h:38
OTest2::ExcCatcherOrdinary::catchException
virtual bool catchException(const Context &context_, std::function< void(const Context &)> ftor_, std::string &message_) noexcept
Catch unexpected exceptions.
Definition:
exccatcherordinary.cpp:38
exccatcherordinary.h
Generated by
1.8.17