1 /*
2 * Copyright (C) 2009, Google Inc.
3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
4 *
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Distribution License v. 1.0 which is available at
7 * https://www.eclipse.org/org/documents/edl-v10.php.
8 *
9 * SPDX-License-Identifier: BSD-3-Clause
10 */
11
12 package org.eclipse.jgit.pgm;
13
14 /**
15 * Indicates a {@link org.eclipse.jgit.pgm.TextBuiltin} implementation has
16 * failed during execution.
17 * <p>
18 * Typically the stack trace for a Die exception is not shown to the user as it
19 * may indicate a simple error condition that the end-user can fix on their own,
20 * without needing a screen of Java stack frames.
21 */
22 public class Die extends RuntimeException {
23 private static final long serialVersionUID = 1L;
24
25 private boolean aborted;
26
27 /**
28 * Construct a new message explaining what has gone wrong.
29 *
30 * @param why
31 * the message to show to the end-user.
32 */
33 public Die(String why) {
34 super(why);
35 }
36
37 /**
38 * Construct a new message explaining what has gone wrong.
39 *
40 * @param why
41 * the message to show to the end-user.
42 * @param cause
43 * why the command has failed.
44 */
45 public Die(String why, Throwable cause) {
46 super(why, cause);
47 }
48
49 /**
50 * Construct a new exception reflecting the fact that the
51 * command execution has been aborted before running.
52 *
53 * @param aborted boolean indicating the fact the execution has been aborted
54 * @since 3.4
55 */
56 public Die(boolean aborted) {
57 this(aborted, null);
58 }
59
60 /**
61 * Construct a new exception reflecting the fact that the command execution
62 * has been aborted before running.
63 *
64 * @param aborted
65 * boolean indicating the fact the execution has been aborted
66 * @param cause
67 * can be null
68 * @since 4.2
69 */
70 public Die(boolean aborted, Throwable cause) {
71 super(cause != null ? cause.getMessage() : null, cause);
72 this.aborted = aborted;
73 }
74
75 /**
76 * Check if this exception should cause the execution to be aborted.
77 *
78 * @return boolean indicating that the execution should be aborted
79 * @since 3.4
80 */
81 public boolean isAborted() {
82 return aborted;
83 }
84 }