blob: 27937918024672f15debae7590393e8bf0a25ee0 [file] [log] [blame]
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +00001/*
2 * Copyright (c) 2023 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010024#ifndef COMPUTE_KERNEL_WRITER_INCLUDE_CKW_ERROR_H
25#define COMPUTE_KERNEL_WRITER_INCLUDE_CKW_ERROR_H
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000026
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010027#include <stdexcept>
Nikolaj Jensenacea4072023-07-03 09:44:42 +010028#include <string>
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000029
30namespace ckw
31{
32/** Creates the error message
33 *
34 * @param[in] file File in which the error occurred.
35 * @param[in] func Function in which the error occurred.
36 * @param[in] line Line in which the error occurred.
37 * @param[in] msg Message to display before abandoning.
38 *
39 * @return status containing the error
40 */
Nikolaj Jensenacea4072023-07-03 09:44:42 +010041std::string
42create_error_msg(const std::string &file, const std::string &func, const std::string &line, const std::string &msg);
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000043
44/** Print the given message then throw an std::runtime_error.
45 *
46 * @param[in] msg Message to display.
47 */
Nikolaj Jensenacea4072023-07-03 09:44:42 +010048#define COMPUTE_KERNEL_WRITER_ERROR_ON_MSG(msg) \
49 do \
50 { \
51 const std::string arg0(__FILE__); \
52 const std::string arg1(__func__); \
53 const std::string arg2(std::to_string(__LINE__)); \
54 const std::string arg3(msg); \
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000055 std::runtime_error(create_error_msg(arg0, arg1, arg2, arg3)); \
56 } while(false)
57
58} // namespace ckw
59
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010060#endif /* COMPUTE_KERNEL_WRITER_INCLUDE_CKW_ERROR_H */