Expose Cause in Variable
| class TransmissionParser { |
| static Transmission parse(String rawMessage) { |
| if (rawMessage != null |
| && rawMessage.length() != Transmission.MESSAGE_LENGTH) { |
» | throw new IllegalArgumentException( |
| String.format("Expected %d, but got %d characters in '%s'", |
| Transmission.MESSAGE_LENGTH, rawMessage.length(), |
| rawMessage)); |
| } |
| |
| String rawId = rawMessage.substring(0, Transmission.ID_LENGTH); |
| String rawContent = rawMessage.substring(Transmission.ID_LENGTH); |
| try { |
| int id = Integer.parseInt(rawId); |
| String content = rawContent.trim(); |
| return new Transmission(id, content); |
| } catch (NumberFormatException e) { |
» | throw new IllegalArgumentException( |
| String.format("Expected number, ... |
Get Java By Comparison now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.