onnxruntime/objectivec/error_utils.h
Vrajang Parikh 67f4a4fd16
Objective-C binding for ORT training (#16127)
### Description
Implement Objective-C binding for `ORTCheckPoint`. Additionally, 
- Modify `onnxruntime_objectivec.cmake` to only include training header
and sources when training flag is enabled
- Enable objective-c binding for `orttraining-mac-ci-pipeline`

### Motivation and Context
This PR is part of implementing Objective-C bindings for training API.
It implements objective-c binding for ORTCheckPoint class. The
objective-C API closely resembles the C++ API.

**Note**: The test for saving checkpoint is skipped as it requires use
of training session. It will be added when the objective-c binding for
`ORTTrainingSession` is added.
2023-06-07 14:01:30 -07:00

34 lines
1.3 KiB
Objective-C

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#import <Foundation/Foundation.h>
#include <exception>
#import "cxx_api.h"
NS_ASSUME_NONNULL_BEGIN
void ORTSaveCodeAndDescriptionToError(int code, const char* description, NSError** error);
void ORTSaveCodeAndDescriptionToError(int code, NSString* description, NSError** error);
void ORTSaveOrtExceptionToError(const Ort::Exception& e, NSError** error);
void ORTSaveExceptionToError(const std::exception& e, NSError** error);
// helper macros to catch and handle C++ exceptions
#define ORT_OBJC_API_IMPL_CATCH(error, failure_return_value) \
catch (const Ort::Exception& e) { \
ORTSaveOrtExceptionToError(e, (error)); \
return (failure_return_value); \
} \
catch (const std::exception& e) { \
ORTSaveExceptionToError(e, (error)); \
return (failure_return_value); \
}
#define ORT_OBJC_API_IMPL_CATCH_RETURNING_BOOL(error) \
ORT_OBJC_API_IMPL_CATCH(error, NO)
#define ORT_OBJC_API_IMPL_CATCH_RETURNING_NULLABLE(error) \
ORT_OBJC_API_IMPL_CATCH(error, nil)
NS_ASSUME_NONNULL_END