KSS Utility
C++ general utilities
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
error.hpp
Go to the documentation of this file.
1 //
2 // FILENAME: error.hpp
3 // AUTHOR: Steven Klassen
4 // CREATED ON: 2011-08-01
5 //
6 // DESCRIPTION: Error handling in the KSS library.
7 //
8 // This file is Copyright (c) 2011 by Klassen Software Solutions. All rights reserved.
9 // Licensing follows the MIT License.
10 //
11 
17 #if !defined(kssutil_error_hpp)
18 #define kssutil_error_hpp
19 
20 #include <exception>
21 #include <functional>
22 #include <string>
23 #include <utility>
24 
25 namespace kss { namespace util {
26 
48  bool tryAll(const std::function<void()>& fn) noexcept;
49 
50  template <class T>
51  std::pair<T, bool> tryAll(const std::function<T()>& fn) noexcept {
52  try {
53  return std::make_pair(std::move(fn()), true);
54  }
55  catch (const std::exception&) {
56  return std::make_pair(T(), false);
57  }
58  }
59 
70  std::string errorDescription(const std::exception& e);
71 
72 }}
73 
74 #endif
bool tryAll(const std::function< void()> &fn) noexcept
std::string errorDescription(const std::exception &e)