|
| 1 | +/* |
| 2 | + * MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2019 Yurii Dubinka |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), |
| 8 | + * to deal in the Software without restriction, including without limitation |
| 9 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | + * and/or sell copies of the Software, and to permit persons to whom |
| 11 | + * the Software is furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included |
| 14 | + * in all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE |
| 22 | + * OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | + */ |
| 24 | +package io.github.dgroup.term4j; |
| 25 | + |
| 26 | +import org.cactoos.Text; |
| 27 | +import org.cactoos.iterable.IterableOf; |
| 28 | + |
| 29 | +/** |
| 30 | + * Application error. |
| 31 | + * |
| 32 | + * Always has the error code which supposed to be exposed to the external |
| 33 | + * parent process like CLI, bash shell, etc. |
| 34 | + * |
| 35 | + * @since 0.1.0 |
| 36 | + */ |
| 37 | +public final class AppException extends Exception { |
| 38 | + |
| 39 | + /** |
| 40 | + * Application exit code. |
| 41 | + */ |
| 42 | + private final Integer exit; |
| 43 | + |
| 44 | + /** |
| 45 | + * Message. |
| 46 | + */ |
| 47 | + private final Iterable<Text> msg; |
| 48 | + |
| 49 | + /** |
| 50 | + * Ctor. |
| 51 | + * @param msg The message to be print to the user. |
| 52 | + */ |
| 53 | + public AppException(final String msg) { |
| 54 | + this(-1, msg); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Ctor. |
| 59 | + * @param msg The message to be print to the user. |
| 60 | + */ |
| 61 | + public AppException(final Text msg) { |
| 62 | + this(-1, msg); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Ctor. |
| 67 | + * @param exit Application exit code to be print to the user. |
| 68 | + * @param msg The message to be print to the user. |
| 69 | + */ |
| 70 | + public AppException(final Integer exit, final Text msg) { |
| 71 | + this(exit, new IterableOf<>(msg)); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Ctor. |
| 76 | + * @param exit Application exit code to be print to the user. |
| 77 | + * @param msg The message to be print to the user. |
| 78 | + */ |
| 79 | + public AppException(final Integer exit, final String msg) { |
| 80 | + this(exit, new IterableOf<>(() -> msg)); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Ctor. |
| 85 | + * @param exit Application exit code to be print to the user. |
| 86 | + * @param msg The message to be print to the user. |
| 87 | + */ |
| 88 | + public AppException(final Integer exit, final Iterable<Text> msg) { |
| 89 | + super(); |
| 90 | + this.exit = exit; |
| 91 | + this.msg = msg; |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Application exit code to be exposed to the parent OS process. |
| 96 | + * @return The code. |
| 97 | + */ |
| 98 | + public Integer exitCode() { |
| 99 | + return this.exit; |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Application error message split by lines. |
| 104 | + * @return The message. |
| 105 | + */ |
| 106 | + public Iterable<Text> message() { |
| 107 | + return this.msg; |
| 108 | + } |
| 109 | +} |
0 commit comments