IST256 : Applications Programming for Information Systems Exceptions
Agenda Connection Activity Teaching: Practice Activity Quiz, Homework Check Teaching: Exceptions Practice Activity Quiz Average
Quiz #3, HW Check Connect Activity After you turn in the quiz, Open Twitter Sentiment 1.0 For a Homework Check
Exceptions are… Exceptional Exceptions represent a class of errors which occur at run-time. We’ve seen these before when run a program and it crashes due to bad input. And we get a TypeError or ValueError. Python provides a mechanism try .. except to catch these errors at run-time and prevent your program from crashing. Exceptions are exceptional. They should ONLY be used to handle unforeseen errors in program input.
Watch Me Code The need for an exception handling: Bad input Good practice of catching the specific error
Try…Except…Finally try: statements-which-might throw-a-runtime-error except exceptionType: code-to-run-when-error-occurs finally: code-to-run-after-try-or-except Optional
Check Yourself: 90 Second Challenge Input: “dc” X ? Y ? Z? Input “4” X? Y? Z?
Help me Code Old Enough to Vote, Exception Style Let’s Revisit our Program which tells you if you’re old enough to vote given you age, but now uses exceptions to handle non-integer input.
Now You Code Quiz Average Write a program to read a series of quiz grades until you enter “quit” (or “Quit”, or “QUIT” – should not mater) After you enter “quit” it should print out the number of quizzes and the average quiz grade. When you enter something that is not a number, the program should say “Invalid quiz grade – please try again” BONUS: When you enter quiz grade not between 0 and 100 it should say “Invalid quiz grade – please try again”
Conclusion Activity NO CONCLUSION ACTIVITY THIS WEEK Your “Ticket Out” Take out a piece of paper. Print your name at the top Write down ONE THING on the paper you learned today. My TA’s will collect your paper on the way out. The activity will be effort graded.