2 * Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.yangtools.yang.common;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.base.MoreObjects;
14 import com.google.common.collect.ImmutableList;
15 import java.util.Arrays;
16 import java.util.List;
17 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
20 * A general base exception for an operation failure.
22 * @author Thomas Pantelis
24 public class OperationFailedException extends Exception {
26 private static final long serialVersionUID = 1L;
28 private final ImmutableList<RpcError> errorList;
31 * Constructs a new instance with the specified detail message and errors.
33 * @param message the detail message
34 * @param errors {@link RpcError} instances that provide additional error information about
37 public OperationFailedException(final String message, final RpcError... errors) {
38 this(message, null, errors);
42 * Constructs a new instance with the specified detail message, cause and errors.
44 * @param message the detail message
45 * @param cause the cause
46 * @param errors {@link RpcError} instances that provide additional error information about
49 public OperationFailedException(final String message, final Throwable cause,
50 final RpcError... errors) {
51 super(requireNonNull(message), cause);
53 if (errors != null && errors.length > 0) {
54 errorList = ImmutableList.copyOf(Arrays.asList(errors));
56 // Add a default RpcError.
57 errorList = ImmutableList.of(RpcResultBuilder.newError(ErrorType.APPLICATION, null,
58 getMessage(), null, null, getCause()));
63 * Returns additional error information about this exception.
65 * @return a List of RpcErrors. There is always at least one RpcError.
67 public List<RpcError> getErrorList() {
72 public String toString() {
73 return MoreObjects.toStringHelper(this).add("message", getMessage())
74 .add("errorList", errorList).toString();