~/ learn/ comp-348/ cards/ Worked build: the Poem-of-the-Day server
1 of 7

Validate the command-line argument and load the poems once, before binding.

Validate the command-line argument and load the poems once, before binding.

Answer

if (args.length != 1) { System.err.println("usage: java PodServer <poems-file>"); System.exit(2); } List<Poem> poems = PoemFile.load(Path.of(args[0])); if (poems.isEmpty()) throw new IllegalStateException("no poems in " + args[0]);

Fail before the port is bound, not after a client connects. Exiting non-zero on a usage error is what lets a marker (or a shell script) tell a misuse from a crash, and the emptiness check turns a silent, useless server into a startup failure you can actually read.

Harold 4e ch9 §Using ServerSockets; ch8 §Investigating Protocols with Telnet

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/c9d71c3f-5b6e-4183-bdf8-8041aa76e7fb/flashcard utf-8 LF