1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package com.ohos.hapsigntool.error; 17 18 /** 19 * Runtime exception for programs. 20 * 21 * @since 2021/12/28 22 */ 23 public class CustomException extends RuntimeException { 24 private ERROR error; 25 26 private String message; 27 28 /** 29 * Create custom exception with params. 30 * 31 * @param error Error enum to throw 32 * @param message Error msg to throw 33 */ CustomException(ERROR error, String message)34 CustomException(ERROR error, String message) { 35 this.error = error; 36 this.message = message; 37 } 38 39 /** 40 * Throw custom exception with params. 41 * 42 * @param error Error enum to throw 43 * @param message Error msg to throw 44 */ throwException(ERROR error, String message)45 public static void throwException(ERROR error, String message) { 46 throw new CustomException(error, message); 47 } 48 getError()49 public ERROR getError() { 50 return error; 51 } 52 setError(ERROR error)53 public void setError(ERROR error) { 54 this.error = error; 55 } 56 57 @Override getMessage()58 public String getMessage() { 59 return message; 60 } 61 setMessage(String message)62 public void setMessage(String message) { 63 this.message = message; 64 } 65 } 66