CS 162 Lecture 19: CS 162 – Lecture 19 – Exception Handling

39 views3 pages
CS 162 Lecture 19 Exception Handling
Exception Handling
o We are talking about c++, other languages are different!
o Deals with unusual circumstances that may require different reactions
o THIS NOT YOUR TYPICAL ERROR HANDLING
Handling bad input that you can predict will be common should not use
Exception Handing
Save Exception Handling for edge cases
What if bad allocation of memory?
Try-throw-catch
o Code in the catch block will execute and then it will continue with the rest of
your program will execute
Oe it hits the ath lok, ad it’s thro, the rest of the try lok ill
not execute
o Try {
Some code, typically the function or piece which may encounter the
unusual error, the basic algorithm for when things go well
Throw Exception_parameter;
Maybe more code
o }
o catch (type_of_exception_param e) {
code to handle the exception
o }
Details
o Not athig o ariale aes, it’s athig o the type
Looks for type match
o You can only have one type that you are catching
Only ONE parameter
Have to create a different catch block if want more
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents