blob: f6b04727f11ae2881df8c5be11d5851f7e3ddab6 [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
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
15package com.google.devtools.build.lib.util;
16
17/**
18 * An exception thrown by various error conditions that are severe enough to halt the command (e.g.
19 * even a --keep_going build). These typically need to signal to the handling code what happened.
mschaller54c9f1e2020-03-20 08:23:50 -070020 * Therefore, these exceptions contain a {@link DetailedExitCode} specifying a numeric exit code and
21 * a detailed failure for the command to return.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010022 *
mschaller54c9f1e2020-03-20 08:23:50 -070023 * <p>When an instance of this exception is thrown, Bazel will try to halt the command as soon as
24 * reasonably possible.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010025 */
26public class AbruptExitException extends Exception {
27
mschaller54c9f1e2020-03-20 08:23:50 -070028 private final DetailedExitCode detailedExitCode;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010029
Googlercc223852020-03-23 09:43:23 -070030 public AbruptExitException(DetailedExitCode detailedExitCode) {
31 super(detailedExitCode.getFailureDetail().getMessage());
mschaller54c9f1e2020-03-20 08:23:50 -070032 this.detailedExitCode = detailedExitCode;
33 }
34
35 public AbruptExitException(DetailedExitCode detailedExitCode, Throwable cause) {
Googlercc223852020-03-23 09:43:23 -070036 super(detailedExitCode.getFailureDetail().getMessage(), cause);
mschaller54c9f1e2020-03-20 08:23:50 -070037 this.detailedExitCode = detailedExitCode;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010038 }
39
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010040 public ExitCode getExitCode() {
mschaller54c9f1e2020-03-20 08:23:50 -070041 return detailedExitCode.getExitCode();
42 }
43
44 public DetailedExitCode getDetailedExitCode() {
45 return detailedExitCode;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010046 }
47}