| Index: src/plugin/Exception.h |
| =================================================================== |
| new file mode 100644 |
| --- /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 T> |
| + 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
|
| + { |
| + try |
| + { |
| + std::rethrow_exception(std::current_exception()); |
| + } |
| + catch (std::system_error& ex) |
| + { |
| + SubHandlers::SystemError(ex, t); |
| + } |
| + catch (std::runtime_error& ex) |
| + { |
| + SubHandlers::RuntimeError(ex, t); |
| + } |
| + catch (std::logic_error& ex) |
| + { |
| + SubHandlers::LogicError(ex, t); |
| + } |
| + catch (std::exception& ex) |
| + { |
| + SubHandlers::Exception(ex, t); |
| + } |
| + catch (...) |
| + { |
| + SubHandlers::Unknown(t); |
| + } |
| + } |
| +}; |
| + |
| +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.
|
| +struct CatchAllReturn |
| +{ |
| + template<typename T> |
| + static ReturnType Handler(T t=T()) |
| + { |
| + 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 (std::system_error& ex) |
| + { |
| + return SubHandlers::SystemError(ex, t); |
| + } |
| + catch (std::runtime_error& ex) |
| + { |
| + return SubHandlers::RuntimeError(ex, t); |
| + } |
| + catch (std::logic_error& ex) |
| + { |
| + return SubHandlers::LogicError(ex, t); |
| + } |
| + catch (std::exception& ex) |
| + { |
| + return SubHandlers::Exception(ex, t); |
| + } |
| + catch (...) |
| + { |
| + return SubHandlers::Unknown(t); |
| + } |
| + } |
| +}; |