From 1e1ddd801b14f261f5dd1b24d9b7bcae188ef9a6 Mon Sep 17 00:00:00 2001 From: Nick Glorioso Date: Fri, 22 Apr 2022 12:31:24 -0700 Subject: [PATCH] Update example for SystemExitOutsideMain to more accurately describe the problem PiperOrigin-RevId: 443731509 --- docs/bugpattern/SystemExitOutsideMain.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/bugpattern/SystemExitOutsideMain.md b/docs/bugpattern/SystemExitOutsideMain.md index ca9c62660a8..4fc6e89d523 100644 --- a/docs/bugpattern/SystemExitOutsideMain.md +++ b/docs/bugpattern/SystemExitOutsideMain.md @@ -10,16 +10,17 @@ For example, prefer this: ```java public static void main(String[] args) { try { - doSomething(args); + doSomething(args[0]); } catch (MyUncheckedException e) { System.err.println(e.getMessage()); System.exit(1); } } -private static void doSomething(args) { +// In library code +public static void doSomething(String s) { try { - doSomethingElse(...); + doSomethingElse(s); } catch (MyCheckedException e) { throw new MyUncheckedException(e); } @@ -30,8 +31,13 @@ to this: ```java public static void main(String[] args) { + doSomething(args[0]); +} + +// In library code +public static void doSomething(String s) { try { - doSomething(...); + doSomethingElse(s) } catch (MyCheckedException e) { System.err.println(e.getMessage()); System.exit(1);