001/*
002 * Copyright 2009-2017 UnboundID Corp.
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2009-2017 UnboundID Corp.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.util;
022
023
024
025/**
026 * This class serves as the base class for all custom runtime exception types
027 * defined in the LDAP SDK.
028 */
029@NotExtensible()
030@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
031public abstract class LDAPSDKRuntimeException
032       extends RuntimeException
033{
034  /**
035   * The serial version UID for this serializable class.
036   */
037  private static final long serialVersionUID = -805259180160427851L;
038
039
040
041  /**
042   * Creates a new instance of this exception with the provided message.
043   *
044   * @param  message  The message to use for this exception.
045   */
046  protected LDAPSDKRuntimeException(final String message)
047  {
048    super(message);
049  }
050
051
052
053  /**
054   * Creates a new instance of this exception with the provided message and
055   * cause.
056   *
057   * @param  message  The message to use for this exception.
058   * @param  cause    The underlying cause for this exception.  It may be
059   *                  {@code null} if no cause is available.
060   */
061  protected LDAPSDKRuntimeException(final String message, final Throwable cause)
062  {
063    super(message, cause);
064  }
065
066
067
068  /**
069   * Retrieves a string representation of this exception.
070   *
071   * @return  A string representation of this exception.
072   */
073  @Override()
074  public final String toString()
075  {
076    final StringBuilder buffer = new StringBuilder();
077    toString(buffer);
078    return buffer.toString();
079  }
080
081
082
083  /**
084   * Appends a string representation of this exception to the provided buffer.
085   *
086   * @param  buffer  The buffer to which the string representation of this
087   *                 exception is to be appended.
088   */
089  public void toString(final StringBuilder buffer)
090  {
091    buffer.append(super.toString());
092  }
093
094
095
096  /**
097   * Retrieves a string representation of this exception suitable for use in
098   * messages.
099   *
100   * @return  A string representation of this exception suitable for use in
101   *          messages.
102   */
103  public String getExceptionMessage()
104  {
105    final String message = getMessage();
106    if (message == null)
107    {
108      return toString();
109    }
110    else
111    {
112      return message;
113    }
114  }
115}