001/*
002 * Copyright 2002-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.messaging;
018
019import org.springframework.core.NestedRuntimeException;
020
021/**
022 * The base exception for any failures related to messaging.
023 *
024 * @author Mark Fisher
025 * @author Gary Russell
026 * @since 4.0
027 */
028@SuppressWarnings("serial")
029public class MessagingException extends NestedRuntimeException {
030
031        private final Message<?> failedMessage;
032
033
034        public MessagingException(Message<?> message) {
035                super(null);
036                this.failedMessage = message;
037        }
038
039        public MessagingException(String description) {
040                super(description);
041                this.failedMessage = null;
042        }
043
044        public MessagingException(String description, Throwable cause) {
045                super(description, cause);
046                this.failedMessage = null;
047        }
048
049        public MessagingException(Message<?> message, String description) {
050                super(description);
051                this.failedMessage = message;
052        }
053
054        public MessagingException(Message<?> message, Throwable cause) {
055                super(null, cause);
056                this.failedMessage = message;
057        }
058
059        public MessagingException(Message<?> message, String description, Throwable cause) {
060                super(description, cause);
061                this.failedMessage = message;
062        }
063
064
065        public Message<?> getFailedMessage() {
066                return this.failedMessage;
067        }
068
069        @Override
070        public String toString() {
071                return super.toString() + (this.failedMessage == null ? ""
072                                : (", failedMessage=" + this.failedMessage));
073        }
074
075}