1 package org.metricshub.jawk;
2
3 /*-
4 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5 * Jawk
6 * ჻჻჻჻჻჻
7 * Copyright (C) 2006 - 2025 MetricsHub
8 * ჻჻჻჻჻჻
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Lesser Public License for more details.
18 *
19 * You should have received a copy of the GNU General Lesser Public
20 * License along with this program. If not, see
21 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
23 */
24
25 /**
26 * With this Exception, any part of the code may request a
27 * <code>System.exit(code)</code> call with a specific code.
28 *
29 * @author Danny Daglas
30 */
31 public class ExitException extends Exception {
32
33 private static final long serialVersionUID = 1L;
34
35 /** Constant <code>EXIT_CODE_OK=0</code> */
36 public static final int EXIT_CODE_OK = 0;
37
38 /** The exit code being returned */
39 private final int code;
40
41 /**
42 * Request exit with the <code>EXIT_CODE_OK</code>.
43 */
44 public ExitException() {
45 this(EXIT_CODE_OK);
46 }
47
48 /**
49 * <p>
50 * Constructor for ExitException.
51 * </p>
52 *
53 * @param code a int
54 */
55 public ExitException(int code) {
56 this(code, "");
57 }
58
59 /**
60 * <p>
61 * Constructor for ExitException.
62 * </p>
63 *
64 * @param message a {@link java.lang.String} object
65 */
66 public ExitException(String message) {
67 this(EXIT_CODE_OK, message);
68 }
69
70 /**
71 * <p>
72 * Constructor for ExitException.
73 * </p>
74 *
75 * @param code a int
76 * @param message a {@link java.lang.String} object
77 */
78 public ExitException(int code, String message) {
79 this(code, message, null);
80 }
81
82 /**
83 * <p>
84 * Constructor for ExitException.
85 * </p>
86 *
87 * @param code a int
88 * @param cause a {@link java.lang.Throwable} object
89 */
90 public ExitException(int code, Throwable cause) {
91 this(code, "", cause);
92 }
93
94 /**
95 * <p>
96 * Constructor for ExitException.
97 * </p>
98 *
99 * @param code a int
100 * @param message a {@link java.lang.String} object
101 * @param cause a {@link java.lang.Throwable} object
102 */
103 public ExitException(int code, String message, Throwable cause) {
104 super(message + " (exit-code: " + code + ")", cause);
105 this.code = code;
106 }
107
108 /**
109 * Returns the code to be passed to the <code>System.exit(code)</code> call.
110 *
111 * @return a int
112 */
113 public int getCode() {
114 return code;
115 }
116 }