From 4f239039bb297cb07ee063888bf5722d07d9e987 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 3 Jan 2024 12:43:03 +0200 Subject: [PATCH] Mention exit handler parameter variant of Quarkus.run Fixes: #37929 --- docs/src/main/asciidoc/lifecycle.adoc | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/src/main/asciidoc/lifecycle.adoc b/docs/src/main/asciidoc/lifecycle.adoc index 911f10ff02f8b..a528863ac6bf0 100644 --- a/docs/src/main/asciidoc/lifecycle.adoc +++ b/docs/src/main/asciidoc/lifecycle.adoc @@ -111,6 +111,42 @@ public class Main { } ---- +[TIP] +==== +`Quarkus.run` also provides a version that allows the code to handle errors. +For example: + +[source,java] +---- +package com.acme; + +import io.quarkus.runtime.Quarkus; +import io.quarkus.runtime.QuarkusApplication; +import io.quarkus.runtime.annotations.QuarkusMain; + +@QuarkusMain +public class Main { + public static void main(String... args) { + Quarkus.run(MyApp.class, + (exitCode, exception) -> { + // do whatever + }, + args); + } + + public static class MyApp implements QuarkusApplication { + + @Override + public int run(String... args) throws Exception { + System.out.println("Do startup logic here"); + Quarkus.waitForExit(); + return 0; + } + } +} +---- +==== + === Injecting the command line arguments It is possible to inject the arguments that were passed in on the command line: