E-MailRelay
gexceptionsink.cpp
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 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 gexceptionsink.cpp
19///
20
21#include "gdef.h"
22#include "gnetdone.h"
23#include "gexceptionsink.h"
24#include "geventloop.h"
25#include "gassert.h"
26
27namespace GNet
28{
29 namespace ExceptionSinkImp /// An implementation namespace for GNet::ExceptionSink.
30 {
31 struct RethrowExceptionHandler : public GNet::ExceptionHandler /// An GNet::ExceptionHandler that rethrows.
32 {
33 void onException( GNet::ExceptionSource * , std::exception & , bool ) override
34 {
35 throw ;
36 }
37 } rethrow_exception_handler ;
38 }
39}
40
42 m_eh(type==Type::Null?nullptr:&ExceptionSinkImp::rethrow_exception_handler)
43{
44}
45
47 m_eh(&eh) ,
48 m_esrc(esrc)
49{
50}
51
53 m_eh(eh) ,
54 m_esrc(esrc)
55{
56}
57
59{
60 return m_eh ;
61}
62
64{
65 return m_esrc ;
66}
67
68void GNet::ExceptionSink::call( std::exception & e , bool done )
69{
70 if( m_eh != nullptr )
71 {
72 m_eh->onException( m_esrc , e , done ) ;
73 }
74}
75
77{
78 m_eh = nullptr ;
79 m_esrc = nullptr ;
80}
81
82bool GNet::ExceptionSink::set() const noexcept
83{
84 return m_eh != nullptr ;
85}
86
87// ==
88
90 m_eh(&eh)
91{
92}
93
95 m_eh(eh)
96{
97 G_ASSERT( eh != nullptr ) ;
98}
99
101{
102 return ExceptionSink{ m_eh , source } ;
103}
104
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket/future event...
ExceptionSinkUnbound(ExceptionHandler *eh)
Constructor.
ExceptionSink bind(ExceptionSource *source) const
Returns a sink object with the source pointer set.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
ExceptionHandler * eh() const noexcept
Returns the exception handler pointer.
ExceptionSource * esrc() const noexcept
Returns the exception source pointer.
ExceptionSink(Type=Type::Rethrow, ExceptionSource *source=nullptr) noexcept
Constructor.
void call(std::exception &e, bool done)
Calls the exception handler's onException() method.
void reset() noexcept
Resets the pointers.
bool set() const noexcept
Returns true if eh() is not null.
A mixin base class that identifies the source of an exception when delivered to GNet::ExceptionHandle...
Network classes.
Definition: gdef.h:1115
An GNet::ExceptionHandler that rethrows.
void onException(GNet::ExceptionSource *, std::exception &, bool) override
Called by the event loop when an exception is thrown out of an event loop callback.