
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
33 lines
835 B
Plaintext
33 lines
835 B
Plaintext
== Why is this an issue?
|
|
|
|
There's no reason for a ``++main++`` method to ``++throw++`` anything. After all, what's going to catch it?
|
|
|
|
|
|
Instead, the method should itself gracefully handle any exceptions that may bubble up to it, attach as much contextual information as possible, and perform whatever logging or user communication is necessary, and ``++exit++`` with a non-zero (i.e. non-success) exit code if necessary.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,text]
|
|
----
|
|
public static void main(String args[]) throws Exception { // Noncompliant
|
|
doSomething();
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,text]
|
|
----
|
|
public static void main(String args[]) {
|
|
try {
|
|
doSomething();
|
|
} catch (Throwable t) {
|
|
log.error(t);
|
|
System.exit(1); // Default exit code, 0, indicates success. Non-zero value means failure.
|
|
}
|
|
}
|
|
----
|
|
|