Java : URISyntaxException with Examples
URISyntaxException (Java SE 21 & JDK 21) with Examples.
You will find code examples on most URISyntaxException methods.
Summary
try {
final var uri = new URI("★://example.com/");
} catch (URISyntaxException e) {
System.out.println("URISyntaxException! : " + e.getMessage());
}
// Result
// ↓
//URISyntaxException! : Illegal character in scheme name at index 0: ★://example.com/
Constructors
URISyntaxException (String input, String reason)
final var e = new URISyntaxException("abc", "XYZ");
System.out.println(e); // java.net.URISyntaxException: XYZ: abc
URISyntaxException (String input, String reason, int index)
final var e = new URISyntaxException("abc", "XYZ", 123);
System.out.println(e); // java.net.URISyntaxException: XYZ at index 123: abc
Methods
int getIndex ()
final var e = new URISyntaxException("abc", "XYZ", 123);
System.out.println(e.getMessage()); // XYZ at index 123: abc
System.out.println(e.getInput()); // abc
System.out.println(e.getReason()); // XYZ
System.out.println(e.getIndex()); // 123
String getInput ()
final var e = new URISyntaxException("abc", "XYZ", 123);
System.out.println(e.getMessage()); // XYZ at index 123: abc
System.out.println(e.getInput()); // abc
System.out.println(e.getReason()); // XYZ
System.out.println(e.getIndex()); // 123
String getMessage ()
final var e = new URISyntaxException("abc", "XYZ", 123);
System.out.println(e.getMessage()); // XYZ at index 123: abc
System.out.println(e.getInput()); // abc
System.out.println(e.getReason()); // XYZ
System.out.println(e.getIndex()); // 123
String getReason ()
final var e = new URISyntaxException("abc", "XYZ", 123);
System.out.println(e.getMessage()); // XYZ at index 123: abc
System.out.println(e.getInput()); // abc
System.out.println(e.getReason()); // XYZ
System.out.println(e.getIndex()); // 123
Methods declared in Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
Please see the link below.