1 Exception Handling, Modules, Names Per Brand. 2 Exception Handling An exception is any expression E. To raise the exception, one executes the following.

Slides:



Advertisements
Similar presentations
Chapter 7: User-Defined Functions II
Advertisements

Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Exception Handling The purpose of exception handling is to permit the program to catch and handle errors rather than letting the error occur and suffer.
Exception Handling Chapter 15 2 What You Will Learn Use try, throw, catch to watch for indicate exceptions handle How to process exceptions and failures.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model From kernel to practical language (CTM 2.6) Exceptions (CTM.
CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Memory management, Exceptions, From kernel to practical language.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Linux+ Guide to Linux Certification, Second Edition
Chapter 11 Exception Handling and Event Handling.
© Copyright Eliyahu Brutman Exceptions. © Copyright Eliyahu Brutman Exceptions and Design Patterns - 2 Introduction to Exception Handling Definition:
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Kernel language semantics Carlos Varela RPI Adapted with permission.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Memory management, Exceptions, From kernel to practical language.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Programming Techniques Non-declarative needs (VRH 3.8) Program design in the.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Exception Error handling. Exception 4 n An unusual occurrence during program execution that requires immediate handling n Errors are the most common type.
C++ fundamentals.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Exceptions. Many problems in code are handled when the code is compiled, but not all Some are impossible to catch before the program is run  Must run.
Java Software Solutions Foundations of Program Design Sixth Edition
PZ11A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ11A - Exception handling Programming Language Design.
Chapter 13, Slide 1 Exception Handling Exception handling is a language feature that allows the programmer to handle runtime "exceptional conditions."
Object Oriented Programming
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
9/10/2015CS2104, Lecture 81 Programming Language Concepts, COSC Lecture 8 (Multiple) Threads Semantics.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Linux+ Guide to Linux Certification, Third Edition
10/22/2015COSC , Lecture 51 Programming Language Concepts, COSC Lecture 5 Iteration, Recursion, Exceptions, Type Notation, and Design Methodology.
Introduction to Exception Handling and Defensive Programming.
Exceptions in Java. Exceptions An exception is an object describing an unusual or erroneous situation Exceptions are thrown by a program, and may be caught.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
11. EXCEPTION HANDLING Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
CSCI 383 Object-Oriented Programming & Design Lecture 20 Martin van Bommel.
Error Handling Tonga Institute of Higher Education.
A First Book of ANSI C Fourth Edition Chapter 6 Modularity Using Functions: Part I.
Firoze Abdur Rakib. Syntax errors, also known as parsing errors, are perhaps the most common kind of error you encounter while you are still learning.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
Linux+ Guide to Linux Certification, Second Edition
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Exceptions Exception handling.
Exceptions Lecture 11 COMP 401, Fall /25/2014.
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
1 Exception handling Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 11.1.
1 Practical Issues, Odds and Ends Per Brand. 2 Base Environment - Reference Manual Table of Contents 1 Introduction 2 Type Structure and Description Format.
Linux Administration Working with the BASH Shell.
C++ LANGUAGE MULTIPLE CHOICE QUESTION
Data Abstraction: The Walls
PZ11A Programming Language design and Implementation -4th Edition
CSC201: Computer Programming
Coupling and Cohesion 1.
Java Primer 1: Types, Classes and Operators
Why exception handling in C++?
Object Oriented Concepts -I
Declarative Computation Model Kernel language semantics (Non-)Suspendable statements (VRH ) Carlos Varela RPI October 11, 2007 Adapted with.
Exception Handling In Text: Chapter 14.
A First Book of ANSI C Fourth Edition
Exception handling Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 11.1.
Exception and Event Handling
Exception handling Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 11.1.
Exception Handling.
Exception handling Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 11.1.
Exception handling Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 11.1.
Presentation transcript:

1 Exception Handling, Modules, Names Per Brand

2 Exception Handling An exception is any expression E. To raise the exception, one executes the following statement: –raise E end proc {Eval E ?R} case E of plus(X Y) then {Browse X+Y} [] times(X Y) then {Browse X*Y} else raise illFormedExpression(E) end end end The basic exception handling statement is called a try-statement: try S catch Pattern 1 then S 1 Pattern 2 then S 2 … Pattern n then S n end

3 Semantics Execution is equivalent to executing S if S does not raise an exception. If S raises exception E, and E matches one of the patterns Pattern i, control is passed to the corresponding statement S i. If E does not match any pattern the exception is propagated outside the try- statement until eventually caught by the system, which catches all escaped exceptions. try S catch Pattern 1 then S 1 Pattern 2 then S 2 … Pattern n then S n end

4 Example try {ForAll [plus(5 10) times(6 11) min(7 10)] Eval} catch illFormedExpression(X) then {Browse ’** X **’} end

5 try … catch … finally A try-statement may also specify a final statement S final, which is executed on normal as well as on exceptional exit. try S catch Pattern 1 then S 1 Pattern 2 then S 2 … Pattern n then S n finally S final end Example –Assume that ‘ F ’ is an opened file; the procedure Process/1 manipulates the file in some way; and the procedure CloseFile/1 closes the file. –The following program ensures that the F is closed upon normal or exceptional exit. try {Process F} catch illFormedExpression(X) then {Browse ’** X **’} finally {CloseFile F} end

6 System Exceptions The exceptions raised by the Oz system are records with one of the labels: failure, error, and system. –failure : indicates the attempt to perform an inconsistent equality operation on the store of Oz. –error : indicates a runtime error which should not occur such as applying a nonprocedure to some argument or adding an integer to an atom, etc. –system : indicates a runtime condition because of the environment of the Mozart operating system process, i.e., an unforeseeable situation like a closed file or window; or failing to open a connection between two Mozart processes.

7 proc {One X} X=1 end proc {Two X} X=2 end try {One}={Two} catch failure(...) then {Show caughtFailure} end Here the pattern failure(...) catches any record whose label is failure. When an exception is raised but not handled, an error message is printed in the emulator window (standard error), and the current thread terminates. In stand-alone applications the default behavior is that a message is printed on standard error and the whole application terminates. It is possible to change this behavior to something else that is more desirable for particular applications.

8 Modules and Interfaces A module is a software component that is first-class. A module consists of a collection of Oz entities (procedure, objects and other values) that are constructed together to provide certain related functionality.  A module typically has a number of private entities that are not visible outside the module and a interface the external services of the module.  The interface provides the services of the module.  The lexical scoping of the language and the record data- type suffices to construct modules.

9 declare List local proc {Append... }... end proc {Partition... }... end proc {Sort... }... {Partition...}... end proc {Member...}... end in List = 'export'(append: Append sort: Sort member: Member... ) end {Browse {List.append [1 2 3] [3 4]}} Homemade Module private

10 Modules are software components that may be stateful Functors are specification of modules (stateless) A functor specifies how to create module from other modules (import), the interface of a module (export), and the initialization procedure (define). Functors, Modules and Interfaces functor export append:Append sort:Sort member:Member define proc {Append... }... end proc {Partition...}... end proc {Sort... }... {Partition...}... end proc {Member...}... end end % stored at /home/person/List.oz % compiled to a compiled-functor at file /home/person/List.ozf

11 Functors as first class values Functors, Modules and Interfaces define functor LF export append:Append sort:Sort member:Member define proc {Append... }... end proc {Partition...}... end proc {Sort... }... {Partition...}... end proc {Member...}... end end declare [ List]= {Module.link [ LF ]}

12 Functors Linking functors into modules: declare [ List]= {Module.link [ “ /home/person/list.ozf ” ]} When a functor is linked the statements between define and end are executed. Functors may have import declarations functor import Browser FO at 'file:///home/person/FileOperations.ozf' define {Browser.browse {FO.countLines '/etc/passwd'}} end functors are values like any other entity.

13 Names for Security declare Sensitive={NewName} proc {Service In Out} case In of Sensitive(X Y) then … [] service1(X Y) then … … [] serviceN(X Y)then … else raise unknownRequest end end end % service1, serviceN are guessable % Sensitive is not