2021-04-27 20:06:30 +03:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
2021-05-14 04:47:22 +03:00
|
|
|
#include <exception>
|
|
|
|
|
2023-04-20 09:18:35 +03:00
|
|
|
#import "cxx_api.h"
|
2021-04-27 20:06:30 +03:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
void ORTSaveCodeAndDescriptionToError(int code, const char* description, NSError** error);
|
2023-06-08 00:01:30 +03:00
|
|
|
void ORTSaveCodeAndDescriptionToError(int code, NSString* description, NSError** error);
|
2021-05-14 04:47:22 +03:00
|
|
|
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)
|
2021-04-27 20:06:30 +03:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|