Chapter 8 Errors and Exceptions Overview Handling errors
- Slides: 16
Chapter 8 Errors and Exceptions
Overview Handling errors With return values. With setjmp/longjmp. With exceptions. Preventing resource leaks. Logging and debugging.
Handling errors with return codes. Simple idea but: Makes it easy to ignore errors The code becomes harder to read, write and understand. There is no universal convention for communicating error information.
An example of error checking
Useful C Functions for handling errors errno perror strerror and friends err/warn setjmp/longjmp
Exceptions in C++ Mechanism: try{. . }catch(. . ){. . . }catch(. . . ){. . . }. . . First sequence of code is code to execute. This code can “throw” exceptions which are “caught” by the apprpriate catch phrase.
Managing exceptions Exceptions in java vs C++ (checked or unchecked) Not catching an exception will cause a program crash, -> DOS attack. At least, catch everything at top level to avoid “spilling beans”. Deeper down, catch only what you can handle. Watch for “finally” clauses in Microsoft C++/Java (pp 273/274)
Preventing Resource Leaks Only real security risk is DOS, but can cause serious performance problems. Very hard to track down and identify. Usually manifest themselves only in production Very hard to trace back to their origin. Usually due to seldom traversed instruction paths, like error or exception handlers.
Watch out for multiple returns
Logging and Debugging Centralize the output operation. There are packages for this. Provide a uniform view. Make it easier to change medium, machine, etc. Provide time stamps. Log every important action, including failures! Protect the logs.
A few final words Keep debugging aids out of production Keep back-door access code out of production Clean out Backup files Say “NO” to Easter Eggs.
Resource leaks “gotchas” Watch for multiple return statements In C++, classes can be used to advantage, but watch out for strange modifications.
- Thoughtful comparative and superlative
- Predefined and non predefined exceptions are raised
- Comparativ
- Comparatives safe
- Spl exceptions
- Robust programs
- Stark law exceptions
- Present progressive exceptions
- Exception handler php
- What is microbiology
- Koch's postulates exceptions
- Pasteurization
- Stark law exceptions
- Electronegativity trend exceptions
- Octet exceptions
- What is microbiology
- Shit flows downhill