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