xref: /aosp_15_r20/external/armnn/profiling/common/include/ProfilingException.hpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <stdexcept>
8 #include <string>
9 #include <sstream>
10 
11 namespace arm
12 {
13 
14 namespace pipe
15 {
16 
17 struct Location
18 {
19     const char* m_Function;
20     const char* m_File;
21     unsigned int m_Line;
22 
Locationarm::pipe::Location23     Location(const char* func,
24              const char* file,
25              unsigned int line)
26     : m_Function{func}
27     , m_File{file}
28     , m_Line{line}
29     {
30     }
31 
AsStringarm::pipe::Location32     std::string AsString() const
33     {
34         std::stringstream ss;
35         ss << " at function " << m_Function
36            << " [" << m_File << ':' << m_Line << "]";
37         return ss.str();
38     }
39 
FileLinearm::pipe::Location40     std::string FileLine() const
41     {
42         std::stringstream ss;
43         ss << " [" << m_File << ':' << m_Line << "]";
44         return ss.str();
45     }
46 };
47 
48 /// General Exception class for Profiling code
49 class ProfilingException : public std::exception
50 {
51 public:
ProfilingException(const std::string & message)52     explicit ProfilingException(const std::string& message) : m_Message(message) {};
53 
ProfilingException(const std::string & message,const Location & location)54     explicit ProfilingException(const std::string& message,
55                                 const Location& location) : m_Message(message + location.AsString()) {};
56 
57     /// @return - Error message of ProfilingException
what() const58     virtual const char *what() const noexcept override
59     {
60          return m_Message.c_str();
61     }
62 
63 private:
64     std::string m_Message;
65 };
66 
67 class BackendProfilingException : public ProfilingException
68 {
69 public:
70     using ProfilingException::ProfilingException;
71 };
72 
73 class BadOptionalAccessException : public ProfilingException
74 {
75     using ProfilingException::ProfilingException;
76 };
77 
78 class BufferExhaustion : public ProfilingException
79 {
80 public:
81     using ProfilingException::ProfilingException;
82 };
83 
84 class InvalidArgumentException : public ProfilingException
85 {
86 public:
87     using ProfilingException::ProfilingException;
88 };
89 
90 class TimeoutException : public ProfilingException
91 {
92 public:
93     using ProfilingException::ProfilingException;
94 };
95 
96 class UnimplementedException : public ProfilingException
97 {
98 public:
99     using ProfilingException::ProfilingException;
100 };
101 
102 } // namespace pipe
103 } // namespace arm
104 
105 #define LOCATION() arm::pipe::Location(__func__, __FILE__, __LINE__)
106