Exceptions.shared.cs 1.92 KB
Newer Older
gaoqiong's avatar
gaoqiong committed
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.ML.OnnxRuntime
{

    /// <summary>
    /// Enum conresponding to native onnxruntime error codes. Must be in sync with the native API
    /// </summary>
    internal enum ErrorCode
    {
        Ok = 0,
        Fail = 1,
        InvalidArgument = 2,
        NoSuchFile = 3,
        NoModel = 4,
        EngineError = 5,
        RuntimeException = 6,
        InvalidProtobuf = 7,
        ModelLoaded = 8,
        NotImplemented = 9,
        InvalidGraph = 10,
        ShapeInferenceNotRegistered = 11,
        RequirementNotRegistered = 12,
    }

    /// <summary>
    /// The Exception that is thrown for errors related ton OnnxRuntime
    /// </summary>
    public class OnnxRuntimeException: Exception
    {
        private static Dictionary<ErrorCode, string> errorCodeToString = new Dictionary<ErrorCode, string>()
        {
            { ErrorCode.Ok, "Ok" },
            { ErrorCode.Fail, "Fail" },
            { ErrorCode.InvalidArgument, "InvalidArgument"} ,
            { ErrorCode.NoSuchFile, "NoSuchFile" },
            { ErrorCode.NoModel, "NoModel" },
            { ErrorCode.EngineError, "EngineError" },
            { ErrorCode.RuntimeException, "RuntimeException" },
            { ErrorCode.InvalidProtobuf, "InvalidProtobuf" },
            { ErrorCode.ModelLoaded, "ModelLoaded" },
            { ErrorCode.NotImplemented, "NotImplemented" },
            { ErrorCode.InvalidGraph, "InvalidGraph" },
            { ErrorCode.ShapeInferenceNotRegistered, "ShapeInferenceNotRegistered" },
            { ErrorCode.RequirementNotRegistered, "RequirementNotRegistered" },
        };

        internal OnnxRuntimeException(ErrorCode errorCode, string message)
            :base("[ErrorCode:" + errorCodeToString[errorCode] + "] " + message)
        {
        }
    }


}