001/* 002 * The MIT License 003 * Copyright (c) 2012 Microsoft Corporation 004 * 005 * Permission is hereby granted, free of charge, to any person obtaining a copy 006 * of this software and associated documentation files (the "Software"), to deal 007 * in the Software without restriction, including without limitation the rights 008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 009 * copies of the Software, and to permit persons to whom the Software is 010 * furnished to do so, subject to the following conditions: 011 * 012 * The above copyright notice and this permission notice shall be included in 013 * all copies or substantial portions of the Software. 014 * 015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 021 * THE SOFTWARE. 022 */ 023 024package microsoft.exchange.webservices.data.core.exception.misc; 025 026import java.security.PrivilegedActionException; 027 028/** 029 * The Class ArgumentException. 030 */ 031public class ArgumentException extends IllegalArgumentException { 032 033 /** 034 * Constant serialized ID used for compatibility. 035 */ 036 private static final long serialVersionUID = 2L; 037 038 /** 039 * ParamName that causes the Exception 040 */ 041 private String paramName = null; 042 043 /** 044 * Constructs an <code>IllegalArgumentException</code> with no detail message. 045 */ 046 protected ArgumentException() { 047 super(); 048 } 049 050 /** 051 * Constructs an <code>IllegalArgumentException</code> with the specified detail message. 052 * 053 * @param message the detail message. 054 */ 055 public ArgumentException(String message) { 056 super(message); 057 } 058 059 /** 060 * Constructs an <code>IllegalArgumentException</code> with the specified detail message. 061 * 062 * @param s the detail message. 063 * @param paramName the Name of the Param that causes the exception 064 */ 065 public ArgumentException(String s, String paramName) { 066 super(s); 067 this.paramName = paramName; 068 } 069 070 /** 071 * Constructs a new exception with the specified detail message and cause. 072 * 073 * <p>Note that the detail message associated with <code>cause</code> is <i>not</i> automatically 074 * incorporated in this exception's detail message. 075 * 076 * @param message the detail message (which is saved for later retrieval by the {@link 077 * Throwable#getMessage()} method). 078 * @param cause the cause (which is saved for later retrieval by the {@link Throwable#getCause()} method). 079 * (A <code>null</code> value is permitted, and indicates that the cause is nonexistent or 080 * unknown.) 081 * @since 1.5 082 */ 083 public ArgumentException(String message, Throwable cause) { 084 super(message, cause); 085 } 086 087 /** 088 * Constructs a new exception with the specified cause and a detail message of <code>(cause==null ? null : 089 * cause.toString())</code> (which typically contains the class and detail message of <code>cause</code>). This 090 * constructor is useful for exceptions that are little more than wrappers for other throwables (for 091 * example, {@link PrivilegedActionException}). 092 * 093 * @param cause the cause (which is saved for later retrieval by the {@link Throwable#getCause()} method). 094 * (A <code>null</code> value is permitted, and indicates that the cause is nonexistent or 095 * unknown.) 096 * @since 1.5 097 */ 098 public ArgumentException(Throwable cause) { 099 super(cause); 100 } 101 102 /** 103 * Constructs a new exception with the specified cause and a detail message of <code>(cause==null ? null : 104 * cause.toString())</code> (which typically contains the class and detail message of <code>cause</code>). This 105 * constructor is useful for exceptions that are little more than wrappers for other throwables (for 106 * example, {@link PrivilegedActionException}). 107 * 108 * @param cause the cause (which is saved for later retrieval by the {@link Throwable#getCause()} 109 * method). (A <code>null</code> value is permitted, and indicates that the cause is 110 * nonexistent or unknown.) 111 * @param paramName the Name of the Param that causes the exception 112 */ 113 public ArgumentException(Throwable cause, String paramName) { 114 super(cause); 115 this.paramName = paramName; 116 } 117 118 /** 119 * Initializes a new instance of the System. ArgumentException class with a specified error message and the 120 * name of the parameter that causes this exception. 121 * 122 * @param message The error message that explains the reason for the exception. 123 * @param cause the cause (which is saved for later retrieval by the {@link Throwable#getCause()} 124 * method). (A <code>null</code> value is permitted, and indicates that the cause is 125 * nonexistent or unknown.) 126 * @param paramName the Name of the Param that causes the exception 127 */ 128 public ArgumentException(String message, Throwable cause, String paramName) { 129 super(message + " Parameter that caused " + 130 "the current exception :" + paramName); 131 this.paramName = paramName; 132 } 133 134 /** 135 * Get the Name of the Param that causes the exception 136 * @return the ParamName (or null if not set) 137 */ 138 public String getParamName() { 139 return paramName; 140 } 141 142}