CSCE Student presentation LARRY PARKER

Slides:



Advertisements
Similar presentations
Topics Introduction Types of Errors Exceptions Exception Handling
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Exception Handling – illustrated by Java mMIC-SFT November 2003 Anders P. Ravn Aalborg University.
Lecture 9. 2 Exception  An exception is a unusual, often unpredictable event, detectable by software or hardware, that requires special processing occurring.
Lesson 16 Exceptions Lesson Exceptions1. Murphy’s Law Anything that can go wrong will go wrong Lesson Exceptions2.
Understand Error Handling Software Development Fundamentals LESSON 1.4.
© Copyright Eliyahu Brutman Programming Techniques Course Version 1.0.
1 JMH Associates © 2004, All rights reserved Chapter 4 Structured Exception Handling.
Chapter 13 Exception Handling F Claiming Exceptions F Throwing Exceptions F Catching Exceptions F Rethrowing Exceptions  The finally Clause F Cautions.
Object Oriented Programming
Win32 Programming Lesson 24: More SEH That’s right… you’ll never generate an exception, will you?
Chapter 12: Exception Handling
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Win32 Programming Lesson 25: Unhandled Exceptions Bet you’ve never encountered one of those, eh?
BIO Java 1 Exception Handling Aborting program not always a good idea – can’t lose messages – E-commerce: must ensure correct handling of private.
Sheet 3 HANDLING EXCEPTIONS Advanced Programming using Java By Nora Alaqeel.
Exceptions. Why exceptions? We often strive for writing portable reusable code; we are able to detect errors, however our code may be used for many different.
1 An Exception is… An unusual, often unpredictable event, detectable by software or hardware, that requires special processing An exception handler is.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
CS 161 Introduction to Programming and Problem Solving Chapter 18 Control Flow Through C++ Program Herbert G. Mayer, PSU Status 10/8/2014 Initial content.
Exception Handling How to handle the runtime errors.
C# Exceptions 1 CNS 3260 C#.NET Software Development.
Introduction to Exceptions in Java CS201, SW Development Methods.
1 Handling Errors and Exceptions Chapter 6. 2 Objectives You will be able to: 1. Use the try, catch, and finally statements to handle exceptions. 2. Raise.
Lec.11 (Chapter 11) Exception Jiang (Jen) ZHENG July 13 th, 2005.
C++ Catastrophes “if C allows you to shoot yourself in the foot, then C++ is giving you a machine gun!” James Prince.
Sabrina Wilkes-Morris CSCE 548 Student Presentation
C++ Exceptions.
Exceptions Error Handling and Recovery
16 Exception Handling.
Debugging and Handling Exceptions
Java Programming Fifth Edition
Execution with Unnecessary Privileges
Exceptional Control Flow
Udaya Shyama Pallathadka Ganapathi Bhat CSCE 548 Student Presentation
Failure to protect stored data
Why exception handling in C++?
Chapter 14: Exception Handling
Crash Handlers Riddhiman Ghosh Debugging Applications for
EE422C Software Implementation II
CNS 3260 C# .NET Software Development
Exceptions with Functions
Chapter 17 Templates and Exceptions Part 2
Chapter 12 Exception Handling and Text IO
Exception Handling In Text: Chapter 14.
COP4020 Programming Languages
Exceptions Control Flow
Exceptions.
Exception Handling.
Exceptions 1 CMSC 202.
Lecture 11 Objectives Learn what an exception is.
Problems Debugging is fine and dandy, but remember we divided problems into compile-time problems and runtime problems? Debugging only copes with the former.
Python Syntax Errors and Exceptions
Object-Oriented Programming (OOP) Lecture No. 43
Exception handling Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 11.1.
Ninth step for Learning C++ Programming
Tenth step for Learning C++ Programming
Introduction to Programming
Chapter 12 Exception Handling and Text IO Part 1
Object-Oriented Programming (OOP) Lecture No. 44
Debugging and Handling Exceptions
Exception handling Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 11.1.
Lecture 9.
Chapter 11: Exception Handling
CMSC 202 Exceptions.
Java Programming: From Problem Analysis to Program Design, 4e
Exception handling Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 11.1.
Crash Handlers Riddhiman Ghosh Debugging Applications for
CMSC 202 Lesson 20 Exceptions 1.
Exception handling Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 11.1.
Presentation transcript:

CSCE 548 - Student presentation LARRY PARKER CATCHING EXCEPTIONS CSCE 548 - Student presentation LARRY PARKER

Technical Overview - Exception handling is an often misused feature - What is Exception Handling? - When something goes wrong & the program or system executes immediate actions - Try-Catch blocks are used in programming languages - Windows operating systems/Objective C++ have structured exception handling - 3 types of blocks (try, except, & finally) - UNIX-based operating systems/Linux/Mac Os utilize signal handling

Example #1 Sinful Structured Exception Handling (SEH) - Microsoft-Windows operating system - Uses Structured Exception Handling - Includes keywords (try, except, & finally) int Filter ( DWORD dwExceptionCode ) { if ( dwExceptionCode == EXCEPTION_INTEGER_OVERFLOW ) return EXCEPTION_EXECUTE_HANDLER; else

Example #1 (cont’d) return EXCEPTION_CONTINUE_SEARCH; } void Foo() { __try //invokes the exception handler in the first _except block; operating system creates pop-ups { DoSomethingScary(); } __except( Filter( GetExceptionCode() ) ) //the filter expression is called & makes decisions based on exception code { printf ("Integer overflow!\n"); return E_FAIL; } __finally //If the _try block is exited normally or through an exception, then the _finally block is executed { // Clean up from __try block } }

Example #2 Sinful Signal Handling - UNIX-based operating systems - Signal handlers process various signals - Passed into a process - Errors that happen internal to a process - User-defined signals - Problems - Unstable application being repaired through recovery or performance clean-up tasks may cause additional problems - Common to UNIX-based operating systems (BSD, System V, & Linux)

Example #2 (cont’d) - Signal handlers will resume at the instruction that raised the signal - Ex. A SH for numerical error, such as divide by zero, can easily get into an infinite loop

Detection Methods - Pattern - Using catch(…) - Using catch(Exception) - Using _except(EXCEPTION_EXECUTE_HANDLER) - Code Review - Look for catch blocks that catch all exceptions - Examine whether exception-safe techniques are in use - Search for uninitialized variables - Testing Techniques - Attach a debugger & cause SEH exception handler to break on all first-chance exceptions

Avoidance of Error - Examine code for code that catches exceptions or handles signals - Ensure clean-up tasks occur on properly initialized objects - Review try-except blocks - Ensure no __except blocks handle exceptions - Audit signal handles - Only safe functions are called - Do not ever attempt to handle segmentation faults

Conclusion - Do catch only specific exceptions. - Do handle only structured exceptions that your code can handle. - Do handle signals with safe functions. - Do not catch(…). - Do not catch (Exception). - Do not __except(EXCEPTION_EXECUTE_HANDLER). - Do not handle SIG_SEGV signals, except to log.

References Howard, Michael, David LeBlanc and John Viega. 24 Deadly Sins of Software Security. New York: McGraw-Hill Co., 2010. Kindle Edition