COMPSCI 2S03 Lecture Notes - Lecture 18: Opentext
Document Summary
> throw # of objects when an error occurs during run time. For example, 1/0 will throw the exception divide by zero . Other examples: e. g. scanner. nextint() and user inputs string, it will break the program and throw an exception. Other examples: e. g. scanner. nextint() and user inputs string, it will break the program and throw an exception e. g. open text file and the file does not exist. Need to throw exceptions to validate data (to make sure the user inputed an int into nextint(), using try and catch) You can handle the exception in calculatespeed or in printspeed() Exceptions are propagated and passed to methods that calls them!