/src/main/java/com/google/ie/common/exception/IdeasExchangeException.java

http://thoughtsite.googlecode.com/ · Java · 98 lines · 26 code · 13 blank · 59 comment · 1 complexity · c582849928e7df98f8d3fbf51fb1cae2 MD5 · raw file

  1. /* Copyright 2010 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS.
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License
  14. */
  15. package com.google.ie.common.exception;
  16. /**
  17. * An Object that extends the Exception object.
  18. * This class is used to wrap all business exceptions that can occur in the
  19. * Ideas Exchange project.
  20. *
  21. *
  22. * @author asirohi
  23. *
  24. */
  25. public class IdeasExchangeException extends Exception {
  26. /** A unique identifier for the class */
  27. private static final long serialVersionUID = -6759584646737468342L;
  28. /** An error code that is used to display locale specific error messages */
  29. private String errorCode;
  30. /**
  31. * Constructs a new {@link IdeasExchangeException} object with the specified
  32. * detail message and an error code.
  33. *
  34. * @param errorCode string representing a specific code for the exception.
  35. * @param message string containing the detail message.
  36. */
  37. public IdeasExchangeException(String errorCode, String message) {
  38. this(errorCode, message, null);
  39. }
  40. /**
  41. * Constructs a new {@link IdeasExchangeException} object with the specified
  42. * error code and cause.
  43. *
  44. * @param errorCode an error code of the exception.
  45. * @param message the detail message of the exception.
  46. */
  47. public IdeasExchangeException(String errorCode, Throwable cause) {
  48. this(errorCode, null, cause);
  49. }
  50. /**
  51. * Constructs a new {@link IdeasExchangeException} object with the specified
  52. * error code,message and cause.
  53. *
  54. * @param errorCode an error code of the exception.
  55. * @param message the detail message of the exception.
  56. * @param cause an object of class {@link Throwable} representing the cause
  57. * (which is saved for later retrieval by the Throwable.getCause()
  58. * method).
  59. */
  60. public IdeasExchangeException(String errorCode, String message, Throwable cause) {
  61. super(message, cause);
  62. this.errorCode = errorCode;
  63. }
  64. /**
  65. * Return the error code of the error
  66. *
  67. * @return String
  68. */
  69. public String getErrorCode() {
  70. return errorCode;
  71. }
  72. /**
  73. * Set the error code.
  74. *
  75. * @param errorCode
  76. */
  77. public void setErrorCode(String errorCode) {
  78. this.errorCode = errorCode;
  79. }
  80. @Override
  81. public String toString() {
  82. String s = super.toString();
  83. return (errorCode != null) ? (errorCode + " : " + s) : s;
  84. }
  85. }