Lecture 10 Flashcards
Which three things can cause “problems” with your program? Give examples
- The programmer, error in source code
- The user, giving wrong input (floating-point instead of int)
- The environment, file not found
What three types of errors can a “problem” with your program result in? Rank them from worst to least bad.
Error in results
Error during execution
Error during compilation
What is the difference between an exception and an error?
Exceptions are usually solvable by the programmer (and should be solved), while errors are irrecoverable (e.g. hardware problems, running out of memory).
What two types of exceptions are there? What is the difference between them?
Checked and unchecked exceptions. Java forces you to deal with checked exceptions (so either throw or catch them!)
How do you create a structure to deal with exceptions?
Try { insert code}
catch(exceptionlol e) { insert code}
finally {close your scanner please & insert code}
How do you create your own exception classes and why would you?
You would create your own to be specific about the exception that happened ( you always want to be as specific as possible!) and you do it by creating a class that inherits Exception and creating the methods MyException() and MyException(string s) and implementing them as super() and super(s).