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