EgumCV---CVException.cs

//----------------------------------------------------------------------------
//  Copyright (C) 2004-2012 by EMGU. All rights reserved.       
//----------------------------------------------------------------------------

using System;

namespace Emgu.CV.Util
{
   /// <summary>
   /// The default exception to be thrown when error encounter in Open CV 
   /// </summary>
   [Serializable]
   public class CvException : Exception
   {
      private int _status;
      private string _functionName;
      private String _errMsg;
      private String _fileName;
      private int _line;

      /// <summary>
      /// The numeric code for error status
      /// </summary>
      public int Status
      {
         get { return _status; }
         set { _status = value; }
      }

      /// <summary>
      /// The corresponding error string for the Status code
      /// </summary>
      public String ErrorStr
      {
         get { return CvInvoke.cvErrorStr(Status); }
      }

      /// <summary>
      /// The name of the function the error is encountered
      /// </summary>
      public string FunctionName
      {
         get { return _functionName; }
         set { _functionName = value; }
      }

      /// <summary>
      /// A description of the error
      /// </summary>
      public String ErrorMessage
      {
         get { return _errMsg; }
         set { _errMsg = value; }
      }

      /// <summary>
      /// The source file name where error is encountered
      /// </summary>
      public String FileName
      {
         get { return _fileName; }
         set { _fileName = value; }
      }

      /// <summary>
      /// The line number in the souce where error is encountered
      /// </summary>
      public int Line
      {
         get { return _line; }
         set { _line = value; }
      }

      private CvException()
      {
      }

      /// <summary>
      /// The default exception to be thrown when error is encountered in Open CV 
      /// </summary>
      /// <param name="status">The numeric code for error status</param>
      /// <param name="funcName">The source file name where error is encountered</param>
      /// <param name="errMsg">A description of the error</param>
      /// <param name="fileName">The source file name where error is encountered</param>
      /// <param name="line">The line number in the souce where error is encountered</param>
      public CvException(int status, String funcName, String errMsg, String fileName, int line)
         : base("OpenCV: " + errMsg)
      {
         _status = status;
         _functionName = funcName;
         _errMsg = errMsg;
         _fileName = fileName;
         _line = line;
      }
   }
}

 EgumCV的异常处理代码,看了一下标注都非常清晰。

有两处:1.CvInvoke.cvErrorStr(Status)在CVInvoke类里这样定义

[DllImport(OPENCV_CORE_LIBRARY, CallingConvention = CvInvoke.CvCallingConvention)]
      public static extern String cvErrorStr(int status);

在OpenCV里的原型为:

const char* cvErrorStr( int status );

 

status
错误状态

函数 cvErrorStr 返回指定错误状态编码的原文描述。如果是未知的错误状态该函数返回空 (NULL)指针。

 

2.应该没什么问题,

public CvException(int status, String funcName, String errMsg, String fileName, int line)
         : base("OpenCV: " + errMsg)
      {
         _status = status;
         _functionName = funcName;
         _errMsg = errMsg;
         _fileName = fileName;
         _line = line;
      }

 :base("OpenCV:"+errMsg)调用的基类的构造函数。Exception类里,原型为:

public Exception(string message);

 

 

转载于:https://www.cnblogs.com/kiny/articles/2553036.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值