//----------------------------------------------------------------------------
// 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);