Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+7 votes
asked in CSC212_Spring2019 by (1 point)

1 Answer

+3 votes

If during execution your code throws an exception, then your program will crash unless you write code to prevent the crash. As a software developer, you don't want the program to crash. If a user, however, provides input which could result in a crash, your code can't prevent the exception, but it can provide code to deal with the exception.

To prevent the crash, the code that may throw the exception (ie. result in the exception) would be put in a try block. Then the exception is "caught" in the catch block. In the catch block, you put the code that will excute when the exception occurs. For example, you may want the user to enter a value again. You may simply want to end execution of the program, but more gracefully than crashing.

We will see this come up over the term, but our one example so far is the swap method that we wrote in class and is posted in Moodle.

answered by (1 point)
...