onnxruntime/objectivec/src/error_utils.mm
Edward Chen d21304ceb0
Initial Objective-C API (#7366)
Initial implementation of an Objective-C API.
2021-04-27 10:06:30 -07:00

25 lines
826 B
Text

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#import "src/error_utils.h"
NS_ASSUME_NONNULL_BEGIN
static NSString* const kOrtErrorDomain = @"onnxruntime";
void ORTSaveCodeAndDescriptionToError(int code, const char* descriptionCstr, NSError** error) {
if (!error) return;
NSString* description = [NSString stringWithCString:descriptionCstr
encoding:NSASCIIStringEncoding];
*error = [NSError errorWithDomain:kOrtErrorDomain
code:code
userInfo:@{NSLocalizedDescriptionKey : description}];
}
void ORTSaveExceptionToError(const Ort::Exception& e, NSError** error) {
ORTSaveCodeAndDescriptionToError(e.GetOrtErrorCode(), e.what(), error);
}
NS_ASSUME_NONNULL_END