Exception Handling - PowerPoint PPT Presentation

Loading...

PPT – Exception Handling PowerPoint presentation | free to download - id: 6fb536-N2YwZ



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Exception Handling

Description:

Title: PowerPoint Presentation Author: Christopher D Gill Last modified by: Christopher Gill Created Date: 9/10/2012 7:48:37 PM Document presentation format – PowerPoint PPT presentation

Number of Views:2
Avg rating:3.0/5.0
Slides: 5
Provided by: Christo486
Learn more at: http://www.cse.wustl.edu
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Exception Handling


1
Exception Handling
  • Previous discussion focuses on normal control
    flow
  • Sometimes program reaches a point where it cannot
    continue correctly and in a principled manner
  • Exception handling provides a type-safe way to
    manage control of such exceptional cases
  • Often less efficient, so use sparingly and only
    when needed
  • Exception types and semantics may vary
  • Some languages provide built-in exception types
  • Others (e.g., C11) introduce them via libraries
  • Syntax and semantics also varies between
    languages
  • E.g., C has an explicit try/catch construct
    whereas in other languages you can attach
    handlers to arbitrary blocks
  • Exceptions usually propagate if uncaught, unwind
    stack frames, and may even terminate main
    function of a program

2
Exception Handling
  • Raising/handling exceptions similar to procedure
    calls
  • But, stack unwinds, so cant put activation
    record there
  • Need to find/call handler dynamically
  • One approach is to keep a separate handler stack
  • Nicely general but may be expensive to maintain
    at runtime
  • May be necessary to avoid restricting handler
    semantics
  • C pre-computes address-indexed dispatch table
  • Avoids any cost to code that doesnt use
    exceptions
  • Still somewhat expensive since it needs (e.g.,
    binary) search
  • Search also motivates first-matching-catch-block
    semantics

3
Coroutines and Events
  • Coroutines offer an alternative to nested
    procedures
  • Take turns executing (cooperatively alternating)
  • Detach operation establishes ability to transfer
    control
  • Transfer operation saves program counter in a
    routine, transfers control to current point of
    execution in another
  • Coroutines offer a natural approach to event
    handling
  • Originated in Simula (discrete event simulation
    language)
  • Iterators can use coroutines (but often done more
    simply)
  • In general, event handling involves independent
    code
  • Handling key press vs. mouse move vs. network
    packet
  • The idea is to abstract handlers for each
    distinct event and then coordinate their
    operations (e.g., clicking on a window brings it
    to the foreground and directs subsequent input to
    it)

4
Todays Studio Exercises
  • Well code up ideas from Scott Chapter 8.5-8.8
  • Looking primarily at exceptions (optionally event
    handling)
  • Todays exercises are again in C
  • Please take advantage of the on-line tutorial and
    reference manual pages that are linked on the
    course web site
  • As always, please ask us for help as needed
  • When done, email your answers with subject
    lineControl Abstraction Studio II to
    cse425_at_seas.wustl.edu
About PowerShow.com