commit b944258a233a05226690e3cf52a564a738180a50 parent a26f0a867b0bfd9b4e19cdfac8083c9db1aa8482 Author: Bertrand BRUN <bertrand0brun@gmail.com> Date: Thu, 10 Feb 2011 13:45:03 +0100 Ajout d'une classe d'exception Diffstat:
| A | code/PtiClic/src/exception/PtiClicException.java | | | 47 | +++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 47 insertions(+), 0 deletions(-)
diff --git a/code/PtiClic/src/exception/PtiClicException.java b/code/PtiClic/src/exception/PtiClicException.java @@ -0,0 +1,47 @@ +package exception; + +import java.io.Serializable; + +import com.google.gson.Gson; + +public class PtiClicException extends Exception { + + private static final long serialVersionUID = 1L; + private Error error; + + private static class Error implements Serializable { + + private static final long serialVersionUID = 1L; + private int num; + private String msg; + + public Error() {} + + public Error(int num, String msg) { + this.num = num; + this.msg = msg; + } + + public int getNum() { + return num; + } + + public String getMsg() { + return msg; + } + } + + public PtiClicException(int num, String msg) { + this.error = new Error(num, msg); + } + + public PtiClicException(String json) { + Gson gson = new Gson(); + error = gson.fromJson(json, Error.class); + } + + public String getMessage() { + return "Erreur numero: " + error.getNum() + "\n" + error.getMsg(); + } + +}