FfmpegException.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. namespace Bmp.Core.FFMpeg.CsCorePorts.FFMpegWrap;
  2. /// <summary>
  3. /// FFmpeg Exception
  4. /// </summary>
  5. public class FfmpegException : Exception
  6. {
  7. /// <summary>
  8. /// Throws an <see cref="FfmpegException"/> if the <paramref name="errorCode"/> is less than zero.
  9. /// </summary>
  10. /// <param name="errorCode">The error code.</param>
  11. /// <param name="function">The name of the function that returned the <paramref name="errorCode"/>.</param>
  12. /// <exception cref="FfmpegException"><see cref="FfmpegException"/> with some details (including the <paramref name="errorCode"/> and the <paramref name="function"/>).</exception>
  13. public static void Try(int errorCode, string function)
  14. {
  15. if (errorCode < 0)
  16. throw new FfmpegException(errorCode, function);
  17. }
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="FfmpegException"/> class with an <paramref name="errorCode"/> that got returned by any ffmpeg <paramref name="function"/>.
  20. /// </summary>
  21. /// <param name="errorCode">The error code.</param>
  22. /// <param name="function">The name of the function that returned the <paramref name="errorCode"/>.</param>
  23. public FfmpegException(int errorCode, string function)
  24. : base(string.Format("{0} returned 0x{1:x8}: {2}", function, errorCode, FfmpegCalls.AvStrError(errorCode)))
  25. {
  26. ErrorCode = errorCode;
  27. Function = function;
  28. }
  29. /// <summary>
  30. /// Initializes a new instance of the <see cref="FfmpegException"/> class with a <paramref name="message"/> describing an error that occurred by calling any ffmpeg <paramref name="function"/>.
  31. /// </summary>
  32. /// <param name="message">The message that describes the error.</param>
  33. /// <param name="function">The name of the function that caused the error.</param>
  34. public FfmpegException(string message, string function)
  35. : base(string.Format("{0} failed: {1}", message, function))
  36. {
  37. Function = function;
  38. }
  39. /// <summary>
  40. /// Initializes a new instance of the <see cref="FfmpegException"/> class with a message that describes the error.
  41. /// </summary>
  42. /// <param name="message">The message that describes the error.</param>
  43. public FfmpegException(string message)
  44. : base(message)
  45. {
  46. }
  47. /// <summary>
  48. /// Gets the error code.
  49. /// </summary>
  50. public int ErrorCode { get; private set; }
  51. /// <summary>
  52. /// Gets the ffmpeg function which caused the error.
  53. /// </summary>
  54. public string Function { get; private set; }
  55. }