1 module serialport.exception; 2 3 import std.conv : text; 4 5 import serialport.types; 6 7 /// 8 class SerialPortException : Exception 9 { 10 /// 11 this(string msg, string file=__FILE__, size_t line=__LINE__) 12 @safe pure nothrow @nogc 13 { super(msg, file, line); } 14 } 15 16 /// 17 class UnsupportedException : SerialPortException 18 { 19 /// 20 this(string msg, string file=__FILE__, size_t line=__LINE__) 21 @safe pure nothrow @nogc 22 { super(msg, file, line); } 23 } 24 25 /// 26 class BaudRateUnsupportedException : UnsupportedException 27 { 28 /// 29 uint baudRate; 30 31 /// 32 this(uint br, string file=__FILE__, size_t line=__LINE__) 33 { 34 baudRate = br; 35 super(text("Unsupported baudrate ", br), file, line); 36 } 37 } 38 39 /// 40 class ParityUnsupportedException : UnsupportedException 41 { 42 /// 43 Parity parity; 44 45 /// 46 this(Parity p, string file=__FILE__, size_t line=__LINE__) 47 { 48 parity = p; 49 super(text("Unsupported parity ", p), file, line); 50 } 51 } 52 53 /// 54 class DataBitsUnsupportedException : UnsupportedException 55 { 56 /// 57 DataBits dataBits; 58 59 /// 60 this(DataBits db, string file=__FILE__, size_t line=__LINE__) 61 { 62 dataBits = db; 63 super(text("Unsupported data bits ", db), file, line); 64 } 65 } 66 67 /// 68 class StopBitsUnsupportedException : UnsupportedException 69 { 70 /// 71 StopBits stopBits; 72 73 /// 74 this(StopBits sb, string file=__FILE__, size_t line=__LINE__) 75 { 76 stopBits = sb; 77 super(text("Unsupported stop bits ", sb), file, line); 78 } 79 } 80 81 /// 82 class PortClosedException : SerialPortException 83 { 84 /// 85 string port; 86 87 /// 88 this(string port, string file=__FILE__, size_t line=__LINE__) @safe pure nothrow 89 { 90 this.port = port; 91 super("serial port '" ~ port ~ "' is closed", file, line); 92 } 93 } 94 95 /// 96 class SetupFailException : SerialPortException 97 { 98 /// 99 string port; 100 101 /// 102 this(string port, string reason="", string file=__FILE__, size_t line=__LINE__) 103 @safe pure nothrow 104 { 105 this.port = port; 106 super("Unable to open serial port '" ~ port ~ "'" ~ 107 (reason ? " (" ~ reason ~ ")" : ""), file, line); 108 } 109 } 110 111 /// 112 class IOException : SerialPortException 113 { 114 /// 115 string port; 116 117 /// 118 this(string port, string msg, string file=__FILE__, size_t line=__LINE__) 119 @safe pure nothrow @nogc 120 { super(msg, file, line); } 121 } 122 123 /// 124 class TimeoutException : IOException 125 { 126 /// 127 this(string port, string file=__FILE__, size_t line=__LINE__) 128 @safe pure nothrow 129 { super(port, "Timeout is expires for '" ~ port ~ "'", file, line); } 130 } 131 132 /// 133 class ReadException : IOException 134 { 135 /// 136 this(string port, string msg, string file=__FILE__, size_t line=__LINE__) 137 @safe pure nothrow 138 { super(port, "Failed to read from '" ~ port ~ "': " ~ msg, file, line); } 139 } 140 141 /// 142 class WriteException : IOException 143 { 144 /// 145 this(string port, string msg, string file=__FILE__, size_t line=__LINE__) 146 @safe pure nothrow 147 { super(port, "Failed to write to '" ~ port ~ "': " ~ msg, file, line); } 148 }