2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
18 * @author Sangwan Kwon (sangwan.kwon@samsung.com)
20 * @brief Exception guard and custom exceptions
22 #include "exception.hxx"
24 #include <klay/exception.h>
30 int exceptionGuard(const std::function<int()> &func)
34 } catch (const tanchor::Exception &e) {
38 errStr = "No such file or directory.";
41 errStr = "Out of memory.";
45 errStr = "Permission denied.";
48 errStr = "Internal error.";
52 if (e.error() == TRUST_ANCHOR_ERROR_NOT_INSTALLED)
55 ERROR(SINK, errStr + e.what());
58 } catch (const runtime::Exception &e) {
59 ERROR(SINK, e.what());
60 return TRUST_ANCHOR_ERROR_INTERNAL;
61 } catch (const std::invalid_argument &e) {
62 ERROR(SINK, e.what());
63 return TRUST_ANCHOR_ERROR_INVALID_PARAMETER;
64 } catch (const std::logic_error &e) {
65 ERROR(SINK, e.what());
66 return TRUST_ANCHOR_ERROR_INTERNAL;
67 } catch (const std::exception &e) {
68 ERROR(SINK, e.what());
69 return TRUST_ANCHOR_ERROR_INTERNAL;
71 ERROR(SINK, "Unknown exception occurred.");
72 return TRUST_ANCHOR_ERROR_INTERNAL;
76 Exception::Exception(int ec, const char *file, const char *function,
77 unsigned int line, const std::string &message) noexcept :
79 m_message(FORMAT("[" << file << ":" << line << " " <<
80 function << "()]" << message))
84 const char *Exception::what() const noexcept
86 return this->m_message.c_str();
89 int Exception::error(void) const noexcept
94 } // namespace tanchor