001 /*
002 * Copyright 2013 Erik Kuefler
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014 package com.ekuefler.supereventbus;
015
016 /**
017 * An exception created when an event handler (a method annotated with {@link Subscribe}) fires an
018 * exception during a call to {@link EventBus#post}. The underlying exception is available as the
019 * cause of this exception. This event is not fired by {@link EventBus#post}, but is passed to any
020 * exception handlers registered on the event bus via {@link EventBus#addExceptionHandler}.
021 *
022 * @author ekuefler@gmail.com (Erik Kuefler)
023 */
024 public class EventBusException extends Exception {
025 private final Object source;
026 private final Object event;
027
028 EventBusException(Exception cause, Object source, Object event) {
029 super(cause);
030 this.source = source;
031 this.event = event;
032 }
033
034 /**
035 * Returns the event passed to {@link EventBus#post} that caused the underlying exception to be
036 * thrown.
037 */
038 public Object getEvent() {
039 return event;
040 }
041
042 /**
043 * Returns the object containing the {@link Subscribe}-annotated method that threw the underlying
044 * exception.
045 */
046 public Object getSource() {
047 return source;
048 }
049 }