CMPSC 32 Lecture Notes - Lecture 12: Errno.H, Call Stack, Side Effect

41 views3 pages
26 Sep 2017
School
Course
Professor

Document Summary

There is a way down the call stack. Don"t have to test for an error after each line of code. Can write long stretched of code without error-handling. If the current scope has a catch block, it is executed. If it doesn"t, the exception propagates up the call stack until a catch block is found. Use multiple catch blocks to distinguish between exception types try { somethingthatmightfail(); somethingelsesketchy(); tediousanderrorprone(); catch (int i) { // do something with i catch (std::exception& e) { In nested function/method calls, they are unwound from stack. Destructors are called on all local (automatic) values. If there are pointers to external memory, their owner should release them in the destructor. Stop whe(cid:374) the pro(cid:271)le(cid:373) happe(cid:374)s a(cid:374)d do(cid:374)"t (cid:272)o(cid:374)ti(cid:374)ue. Skip as many function nestings (stack) as needed. Return to state of code right before error happened. Can say what kind of error the function might throw void tediousanderrorprone() throw std::exception;

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