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

Delta Between Two Patch Sets: src/plugin/Exception.h

Issue 5137721374801920: Issue #1173 - Default behavior for catch-all blocks
Left Patch Set: Remove extraneous file; fix spacing Created Feb. 27, 2015, 3:36 p.m.
Right Patch Set: Changed entry point defaults in CPluginClass to match rebase Created March 20, 2015, 9:50 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « adblockplus.gyp ('k') | src/plugin/PluginClass.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** \file Exception.h -- Default behavior for catch-all exception handlers. 18 /** \file Exception.h -- Default behavior for catch-all exception handlers.
19 */ 19 */
20 20
21 template<class SubHandlers> 21 template<typename SubHandlers>
22 struct CatchAllVoid 22 struct CatchAllVoid
23 { 23 {
24 static void Handler() 24 template<typename T>
25 static void Handler(T t = T())
sergei 2015/03/31 14:30:51 Let's rename T to UserData and t to userData.
25 { 26 {
26 try 27 try
27 { 28 {
28 std::rethrow_exception(std::current_exception()); 29 std::rethrow_exception(std::current_exception());
29 } 30 }
30 catch (std::system_error& ex) 31 catch (std::system_error& ex)
sergei 2015/03/31 14:30:51 We don't need non const references, so it is bette
Eric 2015/05/14 14:42:50 Using 'const' here is overly restrictive. It requi
sergei 2015/05/15 13:13:24 Yes, it's more restrictive and requires `SubHandle
31 { 32 {
32 SubHandlers::SystemError(ex); 33 SubHandlers::SystemError(ex, t);
33 } 34 }
34 catch (std::runtime_error& ex) 35 catch (std::runtime_error& ex)
35 { 36 {
36 SubHandlers::RuntimeError(ex); 37 SubHandlers::RuntimeError(ex, t);
37 } 38 }
38 catch (std::logic_error& ex) 39 catch (std::logic_error& ex)
39 { 40 {
40 SubHandlers::LogicError(ex); 41 SubHandlers::LogicError(ex, t);
41 } 42 }
42 catch (std::exception& ex) 43 catch (std::exception& ex)
43 { 44 {
44 SubHandlers::Exception(ex); 45 SubHandlers::Exception(ex, t);
45 } 46 }
46 catch (...) 47 catch (...)
47 { 48 {
48 SubHandlers::Unknown(); 49 SubHandlers::Unknown(t);
49 } 50 }
50 } 51 }
51 }; 52 };
52 53
53 template<class SubHandlers, class ReturnType=SubHandlers::return_t> 54 template<typename SubHandlers, typename ReturnType = typename SubHandlers::Retur nType>
54 struct CatchAllReturn 55 struct CatchAllReturn
55 { 56 {
56 static ReturnType Handler() 57 template<typename T>
58 static ReturnType Handler(T t = T())
57 { 59 {
58 try 60 try
59 { 61 {
60 std::rethrow_exception(std::current_exception()); 62 std::rethrow_exception(std::current_exception());
61 // Apparently VS 2012 does not realize that this function always throws. 63 // Apparently VS 2012 does not realize that this function always throws.
62 // Unless we have an explicit return statement, we get a spurious warning C4715 "not all control paths return a value". 64 // Unless we have an explicit return statement, we get a spurious warning C4715 "not all control paths return a value".
63 return ReturnType(); 65 return ReturnType();
64 } 66 }
65 catch (std::system_error& ex) 67 catch (std::system_error& ex)
66 { 68 {
67 return SubHandlers::SystemError(ex); 69 return SubHandlers::SystemError(ex, t);
68 } 70 }
69 catch (std::runtime_error& ex) 71 catch (std::runtime_error& ex)
70 { 72 {
71 return SubHandlers::RuntimeError(ex); 73 return SubHandlers::RuntimeError(ex, t);
72 } 74 }
73 catch (std::logic_error& ex) 75 catch (std::logic_error& ex)
74 { 76 {
75 return SubHandlers::LogicError(ex); 77 return SubHandlers::LogicError(ex, t);
76 } 78 }
77 catch (std::exception& ex) 79 catch (std::exception& ex)
78 { 80 {
79 return SubHandlers::Exception(ex); 81 return SubHandlers::Exception(ex, t);
80 } 82 }
81 catch (...) 83 catch (...)
82 { 84 {
83 return SubHandlers::Unknown(); 85 return SubHandlers::Unknown(t);
84 } 86 }
85 } 87 }
86 }; 88 };
87
88 /*
89 * NullHandlers is used at present to define the default exception behavior.
90 * When we get non-trivial default exception behavior, this class can move into the unit tests.
91 */
92 struct NullHandlers
93 {
94 static void Unknown() {}
95 static void Exception(std::exception& ex) {}
96 static void LogicError(std::logic_error& ex) { Exception(ex); }
97 static void RuntimeError(std::runtime_error& ex) { Exception(ex); }
98 static void SystemError(std::system_error& ex) { RuntimeError(ex); }
99 };
100
101 void DefaultExceptionBehavior()
102 {
103 CatchAllVoid<NullHandlers>::Handler();
104 }
105
LEFTRIGHT

Powered by Google App Engine
This is Rietveld