2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
16 const char* m_Function;
20 CheckLocation(const char* func,
29 std::string AsString() const
32 ss << " at function " << m_Function
33 << " [" << m_File << ':' << m_Line << "]";
37 std::string FileLine() const
40 ss << " [" << m_File << ':' << m_Line << "]";
45 /// Base class for all ArmNN exceptions so that users can filter to just those.
46 class Exception : public std::exception
49 explicit Exception(const std::string& message);
51 virtual const char* what() const noexcept override;
54 std::string m_Message;
57 class ClRuntimeUnavailableException : public Exception
60 using Exception::Exception;
63 class InvalidArgumentException : public Exception
66 using Exception::Exception;
69 class FileNotFoundException : public Exception
72 using Exception::Exception;
75 class ParseException : public Exception
78 using Exception::Exception;
81 class UnimplementedException : public Exception
84 using Exception::Exception;
85 UnimplementedException();
88 class LayerValidationException : public Exception
90 using Exception::Exception;
93 class GraphValidationException : public Exception
95 using Exception::Exception;
98 template <typename ExceptionType>
99 void ConditionalThrow(bool condition, const std::string& message)
103 throw ExceptionType(message);
108 /// ComparedType must support:
109 /// operator==(const ComparedType&)
110 /// operator<<(ostream&, const ComparedType&)
112 template <typename ExceptionType, typename ComparedType>
113 void ConditionalThrowIfNotEqual(const std::string& message,
114 const ComparedType& leftHandSide,
115 const ComparedType& rightHandSide)
117 if (!(leftHandSide == rightHandSide))
119 std::stringstream ss;
120 ss << message << " : " << leftHandSide << " != " << rightHandSide;
121 throw ExceptionType(ss.str());
127 #define CHECK_LOCATION() armnn::CheckLocation(__func__, __FILE__, __LINE__)