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 com.google.common.base.MoreObjects;
12 import com.google.common.base.Preconditions;
13 import com.google.common.collect.ImmutableList;
14 import java.util.Arrays;
15 import java.util.List;
16 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
19 * A general base exception for an operation failure.
21 * @author Thomas Pantelis
23 public class OperationFailedException extends Exception {
25 private static final long serialVersionUID = 1L;
27 private final List<RpcError> errorList;
30 * Constructs a new instance with the specified detail message and errors.
32 * @param message the detail message
33 * @param errors {@link RpcError} instances that provide additional error information about
36 public OperationFailedException(final String message, final RpcError... errors) {
37 this(message, null, errors);
41 * Constructs a new instance with the specified detail message, cause and errors.
43 * @param message the detail message
44 * @param cause the cause
45 * @param errors {@link RpcError} instances that provide additional error information about
48 public OperationFailedException(final String message, final Throwable cause,
49 final RpcError... errors) {
50 super(Preconditions.checkNotNull(message), cause);
52 if (errors != null && errors.length > 0) {
53 errorList = ImmutableList.copyOf(Arrays.asList(errors));
55 // Add a default RpcError.
56 errorList = ImmutableList.of(RpcResultBuilder.newError(ErrorType.APPLICATION, null,
57 getMessage(), null, null, getCause()));
62 * Returns additional error information about this exception.
64 * @return a List of RpcErrors. There is always at least one RpcError.
66 public List<RpcError> getErrorList() {
71 public String toString() {
72 return MoreObjects.toStringHelper(this).add("message", getMessage())
73 .add("errorList", errorList).toString();