2 * Copyright (c) 2019 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.
17 #ifndef __OOPS_INTERNAL_EXN_H__
18 #define __OOPS_INTERNAL_EXN_H__
23 /// @ brief throw internal exception with message
24 #define INTERNAL_EXN(msg) throw oops::InternalExn(__FILE__, __LINE__, msg)
26 /// @ brief throw internal exception with message and value
27 #define INTERNAL_EXN_V(msg, val) throw oops::InternalExn(__FILE__, __LINE__, msg, val)
32 template <typename T> uint32_t to_uint32(T a) { return static_cast<uint32_t>(a); }
35 * @brief Exception caused by internal error
37 * Note: Please use the above MACROs
39 class InternalExn : public std::exception
42 InternalExn(const char *filename, const int line, const std::string &msg)
43 : _filename(filename), _line(line), _msg(msg)
48 explicit InternalExn(const char *filename, const int line, const std::string &msg, uint32_t val)
49 : _filename(filename), _line(line), _msg(msg + ": " + std::to_string(val))
54 explicit InternalExn(const char *filename, const int line, const std::string &msg,
55 const std::string &val)
56 : _filename(filename), _line(line), _msg(msg + ": " + val)
61 const char *what() const noexcept override { return _full_msg.c_str(); }
64 const std::string _filename;
66 const std::string _msg;
69 void construct_full_msg()
72 "Internal Exception. " + _msg + " [" + _filename + ":" + std::to_string(_line) + "]";
75 std::string _full_msg;
80 #endif // __OOPS_INTERNAL_EXN_H__