2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.vpp.jvpp;
21 * Base exception representing failed operation of JVpp request call
23 public abstract class VppBaseCallException extends Exception {
24 private final String methodName;
25 private final int errorCode;
28 * Constructs an VppCallbackException with the specified api method name and error code.
30 * @param methodName name of a method, which invocation or execution failed
31 * @param errorCode negative error code value associated with this failure
32 * @throws NullPointerException if apiMethodName is null
34 public VppBaseCallException(final String methodName, final int errorCode) {
35 super(String.format("vppApi.%s failed with error code: %d", methodName, errorCode));
36 this.methodName = java.util.Objects.requireNonNull(methodName, "apiMethodName is null!");
37 this.errorCode = errorCode;
39 throw new IllegalArgumentException("Error code must be < 0. Was " + errorCode +
40 " for " + methodName );
45 * Constructs an VppCallbackException with the specified api method name, error description and error code.
47 * @param methodName name of a method, which invocation or execution failed
48 * @param message description of error reason
49 * @param errorCode negative error code value associated with this failure
50 * @throws NullPointerException if apiMethodName is null
52 public VppBaseCallException(final String methodName, final String message, final int errorCode) {
53 super(String.format("vppApi.%s failed: %s (error code: %d)", methodName,message, errorCode));
54 this.methodName = java.util.Objects.requireNonNull(methodName, "apiMethodName is null!");
55 this.errorCode = errorCode;
57 throw new IllegalArgumentException("Error code must be < 0. Was " + errorCode +
58 " for " + methodName );
63 * Returns name of a method, which invocation failed.
67 public String getMethodName() {
72 * Returns the error code associated with this failure.
74 * @return a negative integer error code
76 public int getErrorCode() {