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