1

I tried to throw a custom FormatException by me and try to handle by using try on

try {
   print (' Enter Your age ') ; 
throw FormatException ;
}
on FormatException {
  print('Stop you enter invalid value  ') ;

}

output : didn't handle the exception ? i try using catch(e) and worked fine !

My Question is Why on FormatException won't handle the exception ??

the syntax of tryOn i wrote is true

Minary
  • 79
  • 1
  • 3
  • 11

1 Answers1

1

throw FormatException throws the FormatException type (i.e, an object of type Type), but on FormatException expects to catch an instance a FormatException.

Use throw FormatException() instead (optionally with an error string).

jamesdlin
  • 81,374
  • 13
  • 159
  • 204