| 1 | package net.spy.memcached.ops; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | |
| 6 | /** |
| 7 | * Exceptions thrown when protocol errors occur. |
| 8 | */ |
| 9 | public final class OperationException extends IOException { |
| 10 | |
| 11 | private final OperationErrorType type; |
| 12 | |
| 13 | /** |
| 14 | * General exception (no message). |
| 15 | */ |
| 16 | public OperationException() { |
| 17 | super(); |
| 18 | type=OperationErrorType.GENERAL; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Exception with a message. |
| 23 | * |
| 24 | * @param eType the type of error that occurred |
| 25 | * @param msg the error message |
| 26 | */ |
| 27 | public OperationException(OperationErrorType eType, String msg) { |
| 28 | super(msg); |
| 29 | type=eType; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Get the type of error. |
| 34 | */ |
| 35 | public OperationErrorType getType() { |
| 36 | return type; |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public String toString() { |
| 41 | String rv=null; |
| 42 | if(type == OperationErrorType.GENERAL) { |
| 43 | rv="OperationException: " + type; |
| 44 | } else { |
| 45 | rv="OperationException: " + type + ": " + getMessage(); |
| 46 | } |
| 47 | return rv; |
| 48 | } |
| 49 | } |