View Javadoc
1   package org.sentrysoftware.jawk;
2   
3   /*-
4    * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5    * Jawk
6    * ჻჻჻჻჻჻
7    * Copyright (C) 2006 - 2023 Sentry Software
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>Constructor for ExitException.</p>
50  	 *
51  	 * @param code a int
52  	 */
53  	public ExitException(int code) {
54  		this(code, "");
55  	}
56  
57  	/**
58  	 * <p>Constructor for ExitException.</p>
59  	 *
60  	 * @param message a {@link java.lang.String} object
61  	 */
62  	public ExitException(String message) {
63  		this(EXIT_CODE_OK, message);
64  	}
65  
66  	/**
67  	 * <p>Constructor for ExitException.</p>
68  	 *
69  	 * @param code a int
70  	 * @param message a {@link java.lang.String} object
71  	 */
72  	public ExitException(int code, String message) {
73  		this(code, message, null);
74  	}
75  
76  	/**
77  	 * <p>Constructor for ExitException.</p>
78  	 *
79  	 * @param code a int
80  	 * @param cause a {@link java.lang.Throwable} object
81  	 */
82  	public ExitException(int code, Throwable cause) {
83  		this(code, "", cause);
84  	}
85  
86  	/**
87  	 * <p>Constructor for ExitException.</p>
88  	 *
89  	 * @param code a int
90  	 * @param message a {@link java.lang.String} object
91  	 * @param cause a {@link java.lang.Throwable} object
92  	 */
93  	public ExitException(int code, String message, Throwable cause) {
94  		super(message + " (exit-code: " + code + ")", cause);
95  		this.code = code;
96  	}
97  
98  	/**
99  	 * Returns the code to be passed to the <code>System.exit(code)</code> call.
100 	 *
101 	 * @return a int
102 	 */
103 	public int getCode() {
104 		return code;
105 	}
106 }