OpenCVException.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Runtime.Serialization;
  2. namespace OpenCvSharp;
  3. /// <summary>
  4. /// The default exception to be thrown by OpenCV
  5. /// </summary>
  6. [Serializable]
  7. // ReSharper disable once InconsistentNaming
  8. public class OpenCVException : Exception
  9. {
  10. /// <summary>
  11. /// The numeric code for error status
  12. /// </summary>
  13. public ErrorCode Status { get; set; }
  14. /// <summary>
  15. /// The source file name where error is encountered
  16. /// </summary>
  17. public string FuncName { get; set; }
  18. /// <summary>
  19. /// A description of the error
  20. /// </summary>
  21. public string ErrMsg { get; set; }
  22. /// <summary>
  23. /// The source file name where error is encountered
  24. /// </summary>
  25. public string FileName { get; set; }
  26. /// <summary>
  27. /// The line number in the source where error is encountered
  28. /// </summary>
  29. public int Line { get; set; }
  30. /// <summary>
  31. /// Constructor
  32. /// </summary>
  33. /// <param name="status">The numeric code for error status</param>
  34. /// <param name="funcName">The source file name where error is encountered</param>
  35. /// <param name="errMsg">A description of the error</param>
  36. /// <param name="fileName">The source file name where error is encountered</param>
  37. /// <param name="line">The line number in the source where error is encountered</param>
  38. public OpenCVException(ErrorCode status, string funcName, string errMsg, string fileName, int line)
  39. : base(errMsg)
  40. {
  41. Status = status;
  42. FuncName = funcName;
  43. ErrMsg = errMsg;
  44. FileName = fileName;
  45. Line = line;
  46. }
  47. /// <inheritdoc />
  48. protected OpenCVException(SerializationInfo info, StreamingContext context) : base(info, context)
  49. {
  50. Status = (ErrorCode) info.GetInt32(nameof(Status));
  51. FuncName = info.GetString(nameof(FuncName)) ?? "";
  52. FileName = info.GetString(nameof(FileName)) ?? "";
  53. ErrMsg = info.GetString(nameof(ErrMsg)) ?? "";
  54. Line = info.GetInt32(nameof(Line));
  55. }
  56. /// <inheritdoc />
  57. public override void GetObjectData(SerializationInfo info, StreamingContext context)
  58. {
  59. base.GetObjectData(info, context);
  60. info.AddValue(nameof(Status), Status);
  61. info.AddValue(nameof(FuncName), FuncName);
  62. info.AddValue(nameof(FileName), FileName);
  63. info.AddValue(nameof(ErrMsg), ErrMsg);
  64. info.AddValue(nameof(Line), Line);
  65. }
  66. /// <inheritdoc />
  67. public OpenCVException()
  68. {
  69. Status = 0;
  70. FuncName = "";
  71. ErrMsg = "";
  72. FileName = "";
  73. Line = 0;
  74. }
  75. /// <inheritdoc />
  76. public OpenCVException(string message) : base(message)
  77. {
  78. Status = 0;
  79. FuncName = "";
  80. ErrMsg = "";
  81. FileName = "";
  82. Line = 0;
  83. }
  84. /// <inheritdoc />
  85. public OpenCVException(string message, Exception innerException) : base(message, innerException)
  86. {
  87. Status = 0;
  88. FuncName = "";
  89. ErrMsg = "";
  90. FileName = "";
  91. Line = 0;
  92. }
  93. }