001 /**
002 * Copyright 2008 Mike Kroutikov.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the Lesser GNU General Public License as
006 * published by the Free Software Foundation; either version 3 of
007 * the License, or (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * Lesser GNU General Public License for more details.
013 *
014 * You should have received a copy of the Lesser GNU General Public License
015 * along with this program. If not, see <http://www.gnu.org/licenses/>.
016 */
017 package org.otfeed;
018
019 import org.otfeed.event.OTError;
020
021 /**
022 * Runtime Exception that may hold OTError object describing an error condition
023 * reported by Opentick server.
024 */
025 public final class OTException extends RuntimeException {
026 private static final long serialVersionUID = 2189306294577039319L;
027
028 private final OTError error;
029
030 /**
031 * Creates empty exception.
032 */
033 public OTException() {
034 error = null;
035 }
036
037 /**
038 * Creates exception with text description.
039 *
040 * @param reason description of the reason.
041 */
042 public OTException(String reason) {
043 super(reason);
044 error = null;
045 }
046
047 /**
048 * Creates exception by wrapping some other exception.
049 *
050 * @param wrapped exception that caused the problem.
051 */
052 public OTException(Exception wrapped) {
053 super(wrapped);
054 error = null;
055 }
056
057 /**
058 * Creates exception by wrapping OTError object.
059 *
060 * @param error describes error condition reported by Opentick server.
061 */
062 public OTException(OTError error) {
063 super(error.toString());
064 this.error = error;
065 }
066
067 /**
068 * Returns wrapped OTError object (may be null).
069 *
070 * @return error object.
071 */
072 public OTError getError() { return error; }
073
074 /**
075 * {@inheritDoc}
076 */
077 public String toString() {
078 if(error == null) return super.toString();
079 return "OtfeedException: error=" + error;
080 }
081 }