Index: src/plugin/Exception.h |
diff --git a/src/plugin/Exception.h b/src/plugin/Exception.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cd945c5879ef23058dd23918011456597883ebff |
--- /dev/null |
+++ b/src/plugin/Exception.h |
@@ -0,0 +1,88 @@ |
+/* |
+ * This file is part of Adblock Plus <https://adblockplus.org/>, |
+ * Copyright (C) 2006-2015 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+/** \file Exception.h -- Default behavior for catch-all exception handlers. |
+ */ |
+ |
+template<typename SubHandlers> |
+struct CatchAllVoid |
+{ |
+ template<typename UserData> |
+ static void Handler(UserData userData) |
+ { |
+ try |
+ { |
+ std::rethrow_exception(std::current_exception()); |
+ } |
+ catch (const std::system_error& ex) |
+ { |
+ SubHandlers::Exception(ex, userData); |
+ } |
+ catch (const std::runtime_error& ex) |
+ { |
+ SubHandlers::Exception(ex, userData); |
+ } |
+ catch (const std::logic_error& ex) |
+ { |
+ SubHandlers::Exception(ex, userData); |
+ } |
+ catch (const std::exception& ex) |
+ { |
+ SubHandlers::Exception(ex, userData); |
+ } |
+ catch (...) |
+ { |
+ SubHandlers::Unknown(userData); |
+ } |
+ } |
+}; |
+ |
+template<typename SubHandlers, typename ReturnType = typename SubHandlers::ReturnType> |
+struct CatchAllReturn |
+{ |
+ template<typename UserData> |
+ static ReturnType Handler(UserData userData) |
+ { |
+ try |
+ { |
+ std::rethrow_exception(std::current_exception()); |
+ // Apparently VS 2012 does not realize that this function always throws. |
+ // Unless we have an explicit return statement, we get a spurious warning C4715 "not all control paths return a value". |
+ return ReturnType(); |
+ } |
+ catch (const std::system_error& ex) |
+ { |
+ return SubHandlers::Exception(ex, userData); |
+ } |
+ catch (const std::runtime_error& ex) |
+ { |
+ return SubHandlers::Exception(ex, userData); |
+ } |
+ catch (const std::logic_error& ex) |
+ { |
+ return SubHandlers::Exception(ex, userData); |
+ } |
+ catch (const std::exception& ex) |
+ { |
+ return SubHandlers::Exception(ex, userData); |
+ } |
+ catch (...) |
+ { |
+ return SubHandlers::Unknown(userData); |
+ } |
+ } |
+}; |