File: error_utils.h

package info (click to toggle)
onnxruntime 1.23.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 340,744 kB
  • sloc: cpp: 3,222,135; python: 188,267; ansic: 114,318; asm: 37,927; cs: 36,849; java: 10,962; javascript: 6,811; pascal: 4,126; sh: 2,996; xml: 705; objc: 281; makefile: 67
file content (34 lines) | stat: -rw-r--r-- 1,304 bytes parent folder | download | duplicates (3)
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
// 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