1 module kafkad.exception;
2 
3 import std.exception;
4 
5 mixin template ExceptionCtorMixin() {
6     @safe pure nothrow this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) {
7         super(msg, file, line, next);
8     }
9     @safe pure nothrow this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) {
10         super(msg, file, line, next);
11     }
12 }
13 
14 /// used to mask vibe.d's Exceptions related to connection establishment
15 class ConnectionException : Exception {
16     mixin ExceptionCtorMixin;
17 }
18 
19 /// used to mask vibe.d's Exceptions related to stream I/O
20 class StreamException : Exception {
21     mixin ExceptionCtorMixin;
22 }
23 
24 // kafka specific Exceptions:
25 
26 class OffsetOutOfRangeException : Exception {
27     mixin ExceptionCtorMixin;
28 }
29 
30 class MetadataException : Exception {
31     mixin ExceptionCtorMixin;
32 }
33 
34 class ProtocolException : Exception {
35     mixin ExceptionCtorMixin;
36 }
37 
38 class CrcException : Exception {
39     mixin ExceptionCtorMixin;
40 }
41 
42 /// Catches any exception in the expression and throws a new one specified by E and args
43 /// Examples:
44 /// -----
45 /// import std.conv;
46 /// class MyException : Exception { ... }
47 /// "x".to!int().rethrow!MyException("My message");
48 /// -----
49 T rethrow(E : Exception, T, Args)(lazy scope T expression, Args args) {
50     try {
51         return expression();
52     } catch (Exception) {
53         throw new E(args);
54     }
55 }