1111#include < vector>
1212
1313#include " core/common/common.h"
14+ #include " core/common/status.h"
1415#include " core/common/code_location.h"
1516
1617namespace onnxruntime {
@@ -35,12 +36,44 @@ class OnnxRuntimeException : public std::exception {
3536 /* *
3637 Create a new exception that captures the location it was thrown from.
3738 @param location Location in the source code the exception is being thrown from
39+ @param msg Message containing additional information about the exception cause.
40+ @param category Error category
41+ @param code Error code
42+ */
43+
44+ OnnxRuntimeException (const CodeLocation& location,
45+ const std::string& message,
46+ common::StatusCategory category,
47+ common::StatusCode code) noexcept
48+ : OnnxRuntimeException(location, nullptr , message, category, code) {
49+ }
50+
51+ /* *
52+ Create a new exception that captures the location it was thrown from.
53+ The instance will be created with ONNXRUNTIME category and FAIL code.
54+ @param location Location in the source code the exception is being thrown from
3855 @param failed_condition Optional string containing the condition that failed.
3956 e.g. "tensor.Size() == input.Size()". May be nullptr.
4057 @param msg Message containing additional information about the exception cause.
4158 */
42- OnnxRuntimeException (const CodeLocation& location, const char * failed_condition, const std::string& msg)
43- : location_{location} {
59+ OnnxRuntimeException (const CodeLocation& location, const char * failed_condition, const std::string& msg) noexcept
60+ : OnnxRuntimeException(location, failed_condition, msg,
61+ common::StatusCategory::ONNXRUNTIME, common::StatusCode::FAIL) {
62+ }
63+
64+ /* *
65+ Create a new exception that captures the location it was thrown from.
66+ @param location Location in the source code the exception is being thrown from
67+ @param failed_condition Optional string containing the condition that failed.
68+ e.g. "tensor.Size() == input.Size()". May be nullptr.
69+ @param msg Message containing additional information about the exception cause.
70+ @param category Error category
71+ @param code Error code
72+ */
73+ OnnxRuntimeException (const CodeLocation& location, const char * failed_condition, const std::string& msg,
74+ common::StatusCategory category,
75+ common::StatusCode code)
76+ : location_{location}, category_(category), code_(code) {
4477 std::ostringstream ss;
4578
4679 ss << location.ToString (CodeLocation::kFilenameAndPath ); // output full path in case just the filename is ambiguous
@@ -58,6 +91,14 @@ class OnnxRuntimeException : public std::exception {
5891 what_ = ss.str ();
5992 }
6093
94+ common::StatusCategory Category () const noexcept {
95+ return category_;
96+ }
97+
98+ common::StatusCode Code () const noexcept {
99+ return code_;
100+ }
101+
61102 const char * what () const noexcept override {
62103 return what_.c_str ();
63104 }
@@ -66,6 +107,8 @@ class OnnxRuntimeException : public std::exception {
66107 const CodeLocation location_;
67108 const std::vector<std::string> stacktrace_;
68109 std::string what_;
110+ common::StatusCategory category_;
111+ common::StatusCode code_;
69112};
70113
71114} // namespace onnxruntime
0 commit comments