MCPcopy Create free account
hub / github.com/ShivaBhattacharjee/KeyZen / ExceptionsDemo

Class ExceptionsDemo

data/java/04_exceptions.java:7–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5}
6
7class ExceptionsDemo {
8 static double calculateWpm(int words, int seconds) throws InvalidDurationException {
9 if (seconds <= 0) {
10 throw new InvalidDurationException("seconds must be greater than 0");
11 }
12 return (words * 60.0) / seconds;
13 }
14
15 public static void main(String[] args) {
16 try {
17 System.out.println(calculateWpm(48, 30));
18 System.out.println(calculateWpm(48, 0));
19 } catch (InvalidDurationException e) {
20 System.err.println("Error: " + e.getMessage());
21 }
22 }
23}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected