出口代码映射

出口代码的默认行为如下:spring-doc.cadn.net.cn

指挥注册可以自定义例外退出代码之间的映射。 Spring Shell采用了类似的方法Spring靴关于退出代码,简单来说 融入其中。spring-doc.cadn.net.cn

假设下面显示的异常会从命令中抛出:spring-doc.cadn.net.cn

static class MyException extends RuntimeException {

	private final int code;

	MyException(String msg, int code) {
		super(msg);
		this.code = code;
	}

	public int getCode() {
		return code;
	}
}

可以定义一个映射函数可投掷还有出口代码。你也可以 只需配置一个GO退出代码,它只是配置中的一个语法糖。spring-doc.cadn.net.cn

CommandRegistration.builder()
	.withExitCode()
		.map(MyException.class, 3)
		.map(t -> {
			if (t instanceof MyException) {
				return ((MyException) t).getCode();
			}
			return 0;
		})
		.and()
	.build();
出口代码无法通过基于注释的配置进行自定义