Skip to content

Commit

Permalink
Fix error and return text parsing error.
Browse files Browse the repository at this point in the history
  • Loading branch information
guojin-yan committed Nov 27, 2023
1 parent e44b580 commit 78024a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
37 changes: 19 additions & 18 deletions modules/csharp_api/csharp/exception/handle_exception.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -100,15 +101,15 @@ public static void handler(ExceptionStatus status) {
/// </summary>
/// <exception cref="OVException">general error!</exception>
private static void general_error() {
throw new OVException(ExceptionStatus.GENERAL_ERROR, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.GENERAL_ERROR, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}
/// <summary>
/// Throw NOT_IMPLEMENTED OpenVINOException.
/// </summary>
/// <exception cref="OVException">not implemented!</exception>
private static void not_implemented()
{
throw new OVException(ExceptionStatus.NOT_IMPLEMENTED, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.NOT_IMPLEMENTED, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}

/// <summary>
Expand All @@ -117,7 +118,7 @@ private static void not_implemented()
/// <exception cref="OVException">network not loaded!</exception>
private static void network_not_loaded()
{
throw new OVException(ExceptionStatus.NETWORK_NOT_LOADED, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.NETWORK_NOT_LOADED, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}


Expand All @@ -127,7 +128,7 @@ private static void network_not_loaded()
/// <exception cref="OVException">parameter mismatch!</exception>
private static void parameter_mismatch()
{
throw new OVException(ExceptionStatus.PARAMETER_MISMATCH, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.PARAMETER_MISMATCH, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}

/// <summary>
Expand All @@ -136,7 +137,7 @@ private static void parameter_mismatch()
/// <exception cref="OVException">not found!</exception>
private static void not_found()
{
throw new OVException(ExceptionStatus.NOT_FOUND, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.NOT_FOUND, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}

/// <summary>
Expand All @@ -145,7 +146,7 @@ private static void not_found()
/// <exception cref="OVException">out of bounds!</exception>
private static void out_of_bounds()
{
throw new OVException(ExceptionStatus.OUT_OF_BOUNDS, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.OUT_OF_BOUNDS, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}


Expand All @@ -155,7 +156,7 @@ private static void out_of_bounds()
/// <exception cref="OVException">unexpection!</exception>
private static void unexpection()
{
throw new OVException(ExceptionStatus.UNEXPECTED, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.UNEXPECTED, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}


Expand All @@ -166,87 +167,87 @@ private static void unexpection()
/// <exception cref="OVException">request busy!</exception>
private static void request_busy()
{
throw new OVException(ExceptionStatus.REQUEST_BUSY, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.REQUEST_BUSY, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}
/// <summary>
/// Throw RESULT_NOT_READY OpenVINOException.
/// </summary>
/// <exception cref="OVException">result not ready!</exception>
private static void result_not_ready()
{
throw new OVException(ExceptionStatus.RESULT_NOT_READY, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.RESULT_NOT_READY, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}
/// <summary>
/// Throw OpenVINOException.
/// </summary>
/// <exception cref="OVException">not allocated!</exception>
private static void not_allocated()
{
throw new OVException(ExceptionStatus.NOT_ALLOCATED, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.NOT_ALLOCATED, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}
/// <summary>
/// Throw INFER_NOT_STARTED OpenVINOException.
/// </summary>
/// <exception cref="OVException">infer not started!</exception>
private static void infer_not_started()
{
throw new OVException(ExceptionStatus.INFER_NOT_STARTED, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.INFER_NOT_STARTED, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}
/// <summary>
/// Throw NETWORK_NOT_READ OpenVINOException.
/// </summary>
/// <exception cref="OVException">netword not read!</exception>
private static void netword_not_read()
{
throw new OVException(ExceptionStatus.NETWORK_NOT_READ, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.NETWORK_NOT_READ, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}
/// <summary>
/// Throw INFER_CANCELLED OpenVINOException.
/// </summary>
/// <exception cref="OVException">infer cancelled!</exception>
private static void infer_cancelled()
{
throw new OVException(ExceptionStatus.INFER_CANCELLED, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.INFER_CANCELLED, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}
/// <summary>
/// Throw INVALID_C_PARAM OpenVINOException.
/// </summary>
/// <exception cref="OVException">invalid c param!</exception>
private static void invalid_c_param()
{
throw new OVException(ExceptionStatus.INVALID_C_PARAM, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.INVALID_C_PARAM, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}
/// <summary>
/// Throw UNKNOWN_C_ERROR OpenVINOException.
/// </summary>
/// <exception cref="OVException">unknown c error!</exception>
private static void unknown_c_error()
{
throw new OVException(ExceptionStatus.UNKNOWN_C_ERROR, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.UNKNOWN_C_ERROR, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}
/// <summary>
/// Throw NOT_IMPLEMENT_C_METHOD OpenVINOException.
/// </summary>
/// <exception cref="OVException">not implement c method!</exception>
private static void not_implement_c_method()
{
throw new OVException(ExceptionStatus.NOT_IMPLEMENT_C_METHOD, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.NOT_IMPLEMENT_C_METHOD, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}
/// <summary>
/// Throw UNKNOW_EXCEPTION OpenVINOException.
/// </summary>
/// <exception cref="OVException">unknown exception!</exception>
private static void unknown_exception()
{
throw new OVException(ExceptionStatus.UNKNOW_EXCEPTION, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.UNKNOW_EXCEPTION, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}
/// <summary>
/// Throw PTR_NULL OpenVINOException.
/// </summary>
/// <exception cref="OVException"></exception>
private static void ptr_null_exception()
{
throw new OVException(ExceptionStatus.UNKNOW_EXCEPTION, NativeMethods.ov_get_last_err_msg());
throw new OVException(ExceptionStatus.UNKNOW_EXCEPTION, Marshal.PtrToStringAnsi(NativeMethods.ov_get_last_err_msg()));
}
}
}
2 changes: 1 addition & 1 deletion modules/csharp_api/csharp/native_methods/ov_common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public partial class NativeMethods
/// <returns>The last error msg.</returns>
[DllImport(dll_extern, EntryPoint = "ov_get_last_err_msg",
CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public extern static string ov_get_last_err_msg();
public extern static IntPtr ov_get_last_err_msg();
}
}

0 comments on commit 78024a4

Please sign in to comment.