Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/plugin/Exception.h

Issue 5137721374801920: Issue #1173 - Default behavior for catch-all blocks
Patch Set: Add ExceptionDefault() Created March 5, 2015, 2:56 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus 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 Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 /** \file Exception.h -- Default behavior for catch-all exception handlers.
19 */
20
21 template<typename SubHandlers>
22 struct CatchAllVoid
23 {
24 template<typename T>
25 static void Handler(T t=T())
sergei 2015/03/06 13:51:12 Here and below spaces around '=' are missed and do
Eric 2015/03/06 17:29:59 Fixed.
sergei 2015/03/31 14:30:51 The aim of it is to pass user data to SubHandlers:
Eric 2015/05/14 14:42:50 It doesn't introduce a requirement unless you leav
sergei 2015/05/15 13:13:24 Without default argument value one cannot leave ou
26 {
27 try
28 {
29 std::rethrow_exception(std::current_exception());
30 }
31 catch (std::system_error& ex)
32 {
33 SubHandlers::SystemError(ex, t);
34 }
35 catch (std::runtime_error& ex)
36 {
37 SubHandlers::RuntimeError(ex, t);
38 }
39 catch (std::logic_error& ex)
40 {
41 SubHandlers::LogicError(ex, t);
42 }
43 catch (std::exception& ex)
44 {
45 SubHandlers::Exception(ex, t);
46 }
47 catch (...)
48 {
49 SubHandlers::Unknown(t);
50 }
51 }
52 };
53
54 template<typename SubHandlers, typename ReturnType=SubHandlers::return_t>
sergei 2015/03/06 13:51:12 missed spaces around '='
sergei 2015/03/06 13:51:12 `return_t` is not according to our style
sergei 2015/03/06 13:51:12 `typename` before `SubHandlers::return_t` is misse
Eric 2015/03/06 17:29:59 Done.
Eric 2015/03/06 17:29:59 Done.
55 struct CatchAllReturn
56 {
57 template<typename T>
58 static ReturnType Handler(T t=T())
59 {
60 try
61 {
62 std::rethrow_exception(std::current_exception());
63 // Apparently VS 2012 does not realize that this function always throws.
64 // Unless we have an explicit return statement, we get a spurious warning C4715 "not all control paths return a value".
65 return ReturnType();
66 }
67 catch (std::system_error& ex)
68 {
69 return SubHandlers::SystemError(ex, t);
70 }
71 catch (std::runtime_error& ex)
72 {
73 return SubHandlers::RuntimeError(ex, t);
74 }
75 catch (std::logic_error& ex)
76 {
77 return SubHandlers::LogicError(ex, t);
78 }
79 catch (std::exception& ex)
80 {
81 return SubHandlers::Exception(ex, t);
82 }
83 catch (...)
84 {
85 return SubHandlers::Unknown(t);
86 }
87 }
88 };
OLDNEW

Powered by Google App Engine
This is Rietveld