1 /** 2 * Error handling 3 */ 4 module river.core.exceptions; 5 6 import std.conv : to; 7 8 /** 9 * The type of error that occured 10 */ 11 public enum StreamError 12 { 13 /** 14 * If an operation was attempted on a closed stream 15 */ 16 CLOSED, 17 18 /** 19 * FIXME: Not yet used 20 */ 21 READ_REQUEST_TOO_BIG, 22 23 /** 24 * On a failed operation, can be `read`, `write` etc. 25 */ 26 OPERATION_FAILED 27 } 28 29 /** 30 * Used for any operations on streams whenever an error occurs 31 */ 32 public class StreamException : Exception 33 { 34 /** 35 * The type of error 36 */ 37 private StreamError error; 38 39 /** 40 * Constructs a new `StreamException` of the given sub-error type 41 * and allows an optional message to go along with it 42 * 43 * Params: 44 * error = the `StreamError` describing the kind of error 45 */ 46 this(StreamError error, string msg = "") 47 { 48 string helperMessage = msg.length ? msg : "No further information available"; 49 super("StreamException("~to!(string)(error)~"): "~helperMessage); 50 this.error = error; 51 } 52 53 /** 54 * Returns the type of error that occurred 55 * 56 * Returns: the error as a `StreamError` 57 */ 58 public StreamError getError() 59 { 60 return error; 61 } 62 }