try { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); Date date = dateFormat.parse("30/02/2022"); } catch (ParseException ex) { System.out.println(ex.getMessage()); // Output: Unparseable date: "30/02/2022" }
try { String str = "1.2.3"; NumberFormat format = NumberFormat.getInstance(Locale.US); Number num = format.parse(str); } catch (ParseException ex) { System.out.println(ex.getMessage()); // Output: Unparseable number: "1.2.3" }In both examples, we are using the getMessage() method to get a meaningful message that describes the error that occurred during parsing.