SaslException.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package javax.security.sasl;
  18. import java.io.IOException;
  19. public class SaslException extends IOException {
  20. private static final long serialVersionUID = 4579784287983423626L;
  21. /**
  22. * Serialized field for storing initial cause
  23. */
  24. private Throwable _exception;
  25. public SaslException() {
  26. super();
  27. }
  28. public SaslException(String detail) {
  29. super(detail);
  30. }
  31. public SaslException(String detail, Throwable ex) {
  32. super(detail);
  33. if (ex != null) {
  34. super.initCause(ex);
  35. _exception = ex;
  36. }
  37. }
  38. @Override
  39. public Throwable getCause() {
  40. return _exception;
  41. }
  42. @Override
  43. public Throwable initCause(Throwable cause) {
  44. super.initCause(cause);
  45. _exception = cause;
  46. return this;
  47. }
  48. @Override
  49. public String toString() {
  50. if (_exception == null) {
  51. return super.toString();
  52. }
  53. StringBuilder sb = new StringBuilder(super.toString());
  54. sb.append(", caused by: "); //$NON-NLS-1$
  55. sb.append(_exception.toString());
  56. return sb.toString();
  57. }
  58. }