Attempts to return a HostSpecifier for the given string, throwing an exception if parsing fails. Always use this method in preference to #fromValid(String) for a specifier that is not already known to be valid. @throws ParseException if the specifier is not valid.
(String specifier)
| 110 | |
| 111 | |
| 112 | public static HostSpecifier from(String specifier) throws ParseException { |
| 113 | try { |
| 114 | return fromValid(specifier); |
| 115 | } catch (IllegalArgumentException e) { |
| 116 | // Since the IAE can originate at several different points inside |
| 117 | // fromValid(), we implement this method in terms of that one rather |
| 118 | // than the reverse. |
| 119 | ParseException parseException = new ParseException("Invalid host specifier: " + specifier, 0); |
| 120 | parseException.initCause(e); |
| 121 | throw parseException; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Determines whether {@code specifier} represents a valid {@link HostSpecifier} as described in |