| LEFT | RIGHT |
| 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<typename SubHandlers> | 21 template<typename SubHandlers> |
| 22 struct CatchAllVoid | 22 struct CatchAllVoid |
| 23 { | 23 { |
| 24 template<typename T> | 24 template<typename UserData> |
| 25 static void Handler(T t = T()) | 25 static void Handler(UserData userData) |
| 26 { | 26 { |
| 27 try | 27 try |
| 28 { | 28 { |
| 29 std::rethrow_exception(std::current_exception()); | 29 std::rethrow_exception(std::current_exception()); |
| 30 } | 30 } |
| 31 catch (std::system_error& ex) | 31 catch (const std::system_error& ex) |
| 32 { | 32 { |
| 33 SubHandlers::SystemError(ex, t); | 33 SubHandlers::Exception(ex, userData); |
| 34 } | 34 } |
| 35 catch (std::runtime_error& ex) | 35 catch (const std::runtime_error& ex) |
| 36 { | 36 { |
| 37 SubHandlers::RuntimeError(ex, t); | 37 SubHandlers::Exception(ex, userData); |
| 38 } | 38 } |
| 39 catch (std::logic_error& ex) | 39 catch (const std::logic_error& ex) |
| 40 { | 40 { |
| 41 SubHandlers::LogicError(ex, t); | 41 SubHandlers::Exception(ex, userData); |
| 42 } | 42 } |
| 43 catch (std::exception& ex) | 43 catch (const std::exception& ex) |
| 44 { | 44 { |
| 45 SubHandlers::Exception(ex, t); | 45 SubHandlers::Exception(ex, userData); |
| 46 } | 46 } |
| 47 catch (...) | 47 catch (...) |
| 48 { | 48 { |
| 49 SubHandlers::Unknown(t); | 49 SubHandlers::Unknown(userData); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 template<typename SubHandlers, typename ReturnType = typename SubHandlers::Retur
nType> | 54 template<typename SubHandlers, typename ReturnType = typename SubHandlers::Retur
nType> |
| 55 struct CatchAllReturn | 55 struct CatchAllReturn |
| 56 { | 56 { |
| 57 template<typename T> | 57 template<typename UserData> |
| 58 static ReturnType Handler(T t = T()) | 58 static ReturnType Handler(UserData userData) |
| 59 { | 59 { |
| 60 try | 60 try |
| 61 { | 61 { |
| 62 std::rethrow_exception(std::current_exception()); | 62 std::rethrow_exception(std::current_exception()); |
| 63 // Apparently VS 2012 does not realize that this function always throws. | 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". | 64 // Unless we have an explicit return statement, we get a spurious warning
C4715 "not all control paths return a value". |
| 65 return ReturnType(); | 65 return ReturnType(); |
| 66 } | 66 } |
| 67 catch (std::system_error& ex) | 67 catch (const std::system_error& ex) |
| 68 { | 68 { |
| 69 return SubHandlers::SystemError(ex, t); | 69 return SubHandlers::Exception(ex, userData); |
| 70 } | 70 } |
| 71 catch (std::runtime_error& ex) | 71 catch (const std::runtime_error& ex) |
| 72 { | 72 { |
| 73 return SubHandlers::RuntimeError(ex, t); | 73 return SubHandlers::Exception(ex, userData); |
| 74 } | 74 } |
| 75 catch (std::logic_error& ex) | 75 catch (const std::logic_error& ex) |
| 76 { | 76 { |
| 77 return SubHandlers::LogicError(ex, t); | 77 return SubHandlers::Exception(ex, userData); |
| 78 } | 78 } |
| 79 catch (std::exception& ex) | 79 catch (const std::exception& ex) |
| 80 { | 80 { |
| 81 return SubHandlers::Exception(ex, t); | 81 return SubHandlers::Exception(ex, userData); |
| 82 } | 82 } |
| 83 catch (...) | 83 catch (...) |
| 84 { | 84 { |
| 85 return SubHandlers::Unknown(t); | 85 return SubHandlers::Unknown(userData); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 }; | 88 }; |
| LEFT | RIGHT |