36 lines
984 B
C#
36 lines
984 B
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Nefarius.Peripherals.SerialPort;
|
|
|
|
/// <summary>
|
|
/// Exception used for all errors.
|
|
/// </summary>
|
|
public class CommPortException : ApplicationException
|
|
{
|
|
/// <summary>
|
|
/// Constructor for raising direct exceptions
|
|
/// </summary>
|
|
/// <param name="desc">Description of error</param>
|
|
public CommPortException(string desc) : base(desc)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor for re-raising exceptions from receive thread
|
|
/// </summary>
|
|
/// <param name="e">Inner exception raised on receive thread</param>
|
|
public CommPortException(Exception e) : base("Receive Thread Exception", e)
|
|
{
|
|
}
|
|
|
|
public CommPortException(string message, int error) : base(message)
|
|
{
|
|
Win32Error = error;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The Win32 error that caused the exception.
|
|
/// </summary>
|
|
public int Win32Error { get; } = Marshal.GetLastWin32Error();
|
|
} |