001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.mail; 019 020import java.io.PrintStream; 021import java.io.PrintWriter; 022 023/** 024 * Exception thrown when a checked error occurs in commons-email. 025 * <p> 026 * Adapted from FunctorException in Commons Collections. 027 * <p> 028 * Emulation support for nested exceptions has been removed in {@code Email 1.3}, 029 * supported by JDK ≥ 1.4. 030 * 031 * @since 1.0 032 * @version $Id: EmailException.html 952467 2015-05-23 18:45:36Z tn $ 033 */ 034public class EmailException 035 extends Exception 036{ 037 /** Serializable version identifier. */ 038 private static final long serialVersionUID = 5550674499282474616L; 039 040 /** 041 * Constructs a new <code>EmailException</code> with no 042 * detail message. 043 */ 044 public EmailException() 045 { 046 super(); 047 } 048 049 /** 050 * Constructs a new <code>EmailException</code> with specified 051 * detail message. 052 * 053 * @param msg the error message. 054 */ 055 public EmailException(final String msg) 056 { 057 super(msg); 058 } 059 060 /** 061 * Constructs a new <code>EmailException</code> with specified 062 * nested <code>Throwable</code> root cause. 063 * 064 * @param rootCause the exception or error that caused this exception 065 * to be thrown. 066 */ 067 public EmailException(final Throwable rootCause) 068 { 069 super(rootCause); 070 } 071 072 /** 073 * Constructs a new <code>EmailException</code> with specified 074 * detail message and nested <code>Throwable</code> root cause. 075 * 076 * @param msg the error message. 077 * @param rootCause the exception or error that caused this exception 078 * to be thrown. 079 */ 080 public EmailException(final String msg, final Throwable rootCause) 081 { 082 super(msg, rootCause); 083 } 084 085 /** 086 * Prints the stack trace of this exception to the standard error stream. 087 */ 088 @Override 089 public void printStackTrace() 090 { 091 printStackTrace(System.err); 092 } 093 094 /** 095 * Prints the stack trace of this exception to the specified stream. 096 * 097 * @param out the <code>PrintStream</code> to use for output 098 */ 099 @Override 100 public void printStackTrace(final PrintStream out) 101 { 102 synchronized (out) 103 { 104 final PrintWriter pw = new PrintWriter(out, false); 105 printStackTrace(pw); 106 107 // Flush the PrintWriter before it's GC'ed. 108 pw.flush(); 109 } 110 } 111 112 /** 113 * Prints the stack trace of this exception to the specified writer. 114 * 115 * @param out the <code>PrintWriter</code> to use for output 116 */ 117 @Override 118 public void printStackTrace(final PrintWriter out) 119 { 120 synchronized (out) 121 { 122 super.printStackTrace(out); 123 } 124 } 125}