- Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy patherror_utils.mm
37 lines (26 loc) · 1.24 KB
/
error_utils.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#import"error_utils.h"
NS_ASSUME_NONNULL_BEGIN
staticNSString* constkOrtErrorDomain = @"onnxruntime";
voidORTSaveCodeAndDescriptionToError(int code, constchar* descriptionCstr, NSError** error) {
if (!error) return;
NSString* description = [NSStringstringWithCString:descriptionCstr
encoding:NSUTF8StringEncoding];
*error = [NSErrorerrorWithDomain:kOrtErrorDomain
code:code
userInfo:@{NSLocalizedDescriptionKey : description}];
}
voidORTSaveCodeAndDescriptionToError(int code, NSString* description, NSError** error) {
if (!error) return;
*error = [NSErrorerrorWithDomain:kOrtErrorDomain
code:code
userInfo:@{NSLocalizedDescriptionKey : description}];
}
voidORTSaveOrtExceptionToError(const Ort::Exception& e, NSError** error) {
ORTSaveCodeAndDescriptionToError(e.GetOrtErrorCode(), e.what(), error);
}
voidORTSaveExceptionToError(const std::exception& e, NSError** error) {
ORTSaveCodeAndDescriptionToError(ORT_RUNTIME_EXCEPTION, e.what(), error);
}
NS_ASSUME_NONNULL_END