CSE 425: Control Abstraction II Exception Handling Previous discussion focuses on normal control flow –Sometimes program reaches a point where it cannot.

Slides:



Advertisements
Similar presentations
E-books and E-journals Off-campus This presentation will show you how to log in and access Oxford Brookes Library e-books and e-journals when youre off.
Advertisements

E-books and E-journals Off-campus This presentation will show you how to log in and access Oxford Brookes Library e-books and e-journals when youre off.
Chapter 3 Loaders and Linkers
CSE 425: Semantic Analysis Semantic Analysis Allows rigorous specification of a program’s meaning –Lets (parts of) programming languages be proven correct.
CSE 425: Semantics II Implementing Scopes A symbol table is in essence a dictionary –I.e., every name appears in it, with the info known about it –Usually.
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
CSE341: Programming Languages Lecture 24 Racket Modules, Abstraction with Dynamic Types; Racket Contracts Dan Grossman Fall 2011.
Review Amit Shabtay. March 3rd, 2004 Object Oriented Design Course 2 Review What have we done during the course? Where to learn more? What is for the.
Honors Compilers Addressing of Local Variables Mar 19 th, 2002.
Run time vs. Compile time
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Abstract Data Types and Encapsulation Concepts
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
CSE 425: Intro to Programming Languages and their Design A Few Key Ideas No particular language is a prerequisite for this course –However you should be.
Lecture 22 Miscellaneous Topics 4 + Memory Allocation.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
CSE 425: Object-Oriented Programming II Implementation of OO Languages Efficient use of instructions and program storage –E.g., a C++ object is stored.
Chapter 13, Slide 1 Exception Handling Exception handling is a language feature that allows the programmer to handle runtime "exceptional conditions."
Exception Handling. Definition  The term exception is shorthand for the phrase "exceptional event.“  An exception is an event, which occurs during the.
Object Oriented Programming
1 Exceptions (Section 8.5) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael Scott.
INT-Evry (Masters IT– Soft Eng)IntegrationTesting.1 (OO) Integration Testing What: Integration testing is a phase of software testing in which.
CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
CSE 425: Concurrency III Monitors A monitor is a higher level construct for synchronizing multiple threads’ access to a common code segment –Can implement.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
Copyright © 2005 Elsevier Chapter 8 :: Subroutines and Control Abstraction Programming Language Pragmatics Michael L. Scott.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
CSE 425: Target Machine Architecture Target Machine Details Many architectures can be similar in overall structure –E.g., Von Neumann with CISC instruction.
BIO Java 1 Exception Handling Aborting program not always a good idea – can’t lose messages – E-commerce: must ensure correct handling of private.
CSE 425: Syntax II Context Free Grammars and BNF In context free grammars (CFGs), structures are independent of the other structures surrounding them Backus-Naur.
CSE 425: Control Flow I Categories of Control Flow Constructs Sequencing –order of expressions and statements Selection –if, else, switch Iteration –loops.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
CSE 425: Concurrency II Semaphores and Mutexes Can avoid bad inter-leavings by acquiring locks –Guard access to a shared resource to take turns using it.
JavaScript, Fourth Edition
CSE 425: Control Abstraction I Functions vs. Procedures It is useful to differentiate functions vs. procedures –Procedures have side effects but usually.
Lecture 5 Page 1 CS 111 Online Processes CS 111 On-Line MS Program Operating Systems Peter Reiher.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
CSE 332: C++ Statements C++ Statements In C++ statements are basic units of execution –Each ends with ; (can use expressions to compute values) –Statements.
CSE 425: Syntax I Syntax and Semantics Syntax gives the structure of statements in a language –Allowed ordering, nesting, repetition, omission of symbols.
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
CSCI 383 Object-Oriented Programming & Design Lecture 20 Martin van Bommel.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread.
Assembly Language Co-Routines
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
UNIT 14 1 Websites. Starter 2 1 Starter 1 Divide the students into groups. Ask them to make lists. Ask Students to read their lists. Discuss the most.
Semantic Analysis. Find 6 problems with this code. These issues go beyond syntax.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
Names and Attributes Names are a key programming language feature
Chapter 9 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
Transactional Memory Semaphores, monitors, and conditional critical regions all suffer from limitations based on lock semantics Naïve synchronization may.
Iteration Implemented through loop constructs (e.g., in C++)
Visual programming Chapter 2: Events and Event Handling
Threads Chapter 4.
Parallelism and Concurrency
Delayed Evaluation Special forms in Scheme (e.g., if and cond) do not use applicative order evaluation Only one of two or more expressions is actually.
Languages and Compilers (SProg og Oversættere)
Computational Urban Modelling and Simulation
Threads CSE 2431: Introduction to Operating Systems
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

CSE 425: Control Abstraction II 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., C++11) 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

CSE 425: Control Abstraction II Exception Handling Raising/handling exceptions similar to procedure calls –But, stack unwinds, so can’t 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 doesn’t use exceptions –Still somewhat expensive since it needs (e.g., binary) search –Search also motivates first-matching-catch-block semantics

CSE 425: Control Abstraction II 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)

CSE 425: Control Abstraction II Today’s Studio Exercises We’ll code up ideas from Scott Chapter –Looking primarily at exceptions (optionally event handling) Today’s 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, your answers with subject line“Control Abstraction Studio II” to