001/*
002 * Copyright 2009-2014 UnboundID Corp.
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2009-2014 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   * Creates a new instance of this exception with the provided message.
036   *
037   * @param  message  The message to use for this exception.
038   */
039  protected LDAPSDKRuntimeException(final String message)
040  {
041    super(message);
042  }
043
044
045
046  /**
047   * Creates a new instance of this exception with the provided message and
048   * cause.
049   *
050   * @param  message  The message to use for this exception.
051   * @param  cause    The underlying cause for this exception.  It may be
052   *                  {@code null} if no cause is available.
053   */
054  protected LDAPSDKRuntimeException(final String message, final Throwable cause)
055  {
056    super(message, cause);
057  }
058
059
060
061  /**
062   * Retrieves a string representation of this exception.
063   *
064   * @return  A string representation of this exception.
065   */
066  @Override()
067  public final String toString()
068  {
069    final StringBuilder buffer = new StringBuilder();
070    toString(buffer);
071    return buffer.toString();
072  }
073
074
075
076  /**
077   * Appends a string representation of this exception to the provided buffer.
078   *
079   * @param  buffer  The buffer to which the string representation of this
080   *                 exception is to be appended.
081   */
082  public void toString(final StringBuilder buffer)
083  {
084    buffer.append(super.toString());
085  }
086
087
088
089  /**
090   * Retrieves a string representation of this exception suitable for use in
091   * messages.
092   *
093   * @return  A string representation of this exception suitable for use in
094   *          messages.
095   */
096  public String getExceptionMessage()
097  {
098    final String message = getMessage();
099    if (message == null)
100    {
101      return toString();
102    }
103    else
104    {
105      return message;
106    }
107  }
108}