Java Card Technology Ch06: Exception and Exception Handling Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Computer.

Slides:



Advertisements
Similar presentations
Exceptions Chapter Throwing and Catching Exceptions When a program runs into a problem that it cannot handle, it throws an exception. Exceptions.
Advertisements

Yoshi
Java Card Technology Ch07: Applet Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Computer Science & Engineering.
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.
Exceptions and Exception Handling Carl Alphonce CSE116 March 9, 2007.
Exception Handling Yaodong Bi Exception Handling Java exception handling Try blocks Throwing and re-throwing an exception Catching an.
SE-1020 Dr. Mark L. Hornick 1 More Exception Handling and Throwing Exceptions.
MIT-AITI Lecture 14: Exceptions Handling Errors with Exceptions Kenya 2005.
Exceptions Any number of exceptional circumstances may arise during program execution that cause trouble import java.io.*; class IOExample { public static.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
1 / 89 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 11 Programming Fundamentals using Java 1.
COP INTERMEDIATE JAVA Exception Handling Serialization.
(c) University of Washington11-1 CSC 143 Java More on Exceptions Reading: Ch. 15.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 8 Exception Handling Sections 1-5, 7.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 17 Exceptions and.
Exceptions Three categories of errors: Syntax errors Runtime errors Logic errors Syntax errors: rules of the language have not been followed. Runtime error:
Exceptions Used to signal errors or unexpected situations to calling code Should not be used for problems that can be dealt with reasonably within local.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. COMPSCI 125 Spring 2005 Chapter 8  Errors and Exceptions Throwable class.
Slides prepared by Rose Williams, Binghamton University Chapter 9 More Exception Handling.
12.1 Exceptions The limitations of traditional methods of exception handling Error conditions are a certainty in programming Programmers make.
Introduction to Java Chapter 11 Error Handling. Motivations When a program runs into a runtime error, the program terminates abnormally. How can you handle.
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.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Exception Handling in Java Course Lecture Slides 7 th July 2010 “ Admitting.
Java Card Open Platform Combines tomorrow's technology and platforms C:\Presentations - JavaCard_OpenPlatform.ppt - bsc page 1 Programming.
Java Software Solutions Foundations of Program Design Sixth Edition
Preventing and Correcting Errors
1 Exception Handling Introduction to Exception Handling Exception Handling in PLs –Ada –C++ –Java Sebesta Chapter 14.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 18 Exception Handling.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 9 : Exception Handling King Fahd University of Petroleum & Minerals College of Computer.
Exception Handling 1. Introduction Users may use our programs in an unexpected ways. Due to design errors or coding errors, our programs may fail in unexpected.
06 Exception Handling. 2 Contents What is an Exception? Exception-handling in Java Types of Exceptions Exception Hierarchy try-catch()-finally Statement.
Java Programming Exceptions Handling. Topics: Learn about exceptions Try code and catch Exceptions Use the Exception getMessage() method Throw and catch.
Exception Handling in Java Exception Handling Introduction: After completing this chapter, you will be able to comprehend the nature and kinds.
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
Slides Credit Umair Javed LUMS Web Application Development.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Java Card Technology Ch09: Applet Firewall and Object Sharing Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Computer.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 10.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 15 Exceptions and.
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.
BIO Java 1 Exception Handling Aborting program not always a good idea – can’t lose messages – E-commerce: must ensure correct handling of private.
1 Exception handling in Java Reading for this lecture: Weiss, Section 2.5 (exception handling), p. 47. ProgramLive, chapter 10. I need to know whether.
Java Card Technology Ch08: Working with APDUs
Exceptions and Assertions Chapter 15 – CSCI 1302.
Exception Handling in Java Topics: Introduction Errors and Error handling Exceptions Types of Exceptions Coding Exceptions Summary.
Exceptions Handling Prepared by: Ligemm Mae del Castillo.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
1 Exceptions. 2 Syntax Errors, Runtime Errors, and Logic Errors syntax errors, runtime errors, and logic errors You learned that there are three categories.
1 Chapter 15 Exceptions and Assertions. 2 Objectives F To know what is exception and what is exception handling (§15.2). F To distinguish exception types:
Java Card Technology Ch05: Atomicity and transactions Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Computer.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
Exception. Agenda Exception. Handling Exceptions. The finally Clause.
Exception and Exception Handling. Exception An abnormal event that is likely to happen during program is execution Computer could run out of memory Calling.
Throw, Throws & Try-Catch Statements Explanations and Pictures from: Reference:
ECE122 L23: Exceptions December 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions.
Agenda Introduction Errors and Exception Exception Hierarchy Classification of Exceptions Built in Exceptions Exception Handling in Java User defined.
Exceptions in the Java programming language J. W. Rider.
Object Throwable ErrorException RuntimeException.
Java Exceptions a quick review….
Exceptions, Interfaces & Generics
ATS Application Programming: Java Programming
Java Programming Language
Java Basics Exception Handling.
Exception Handling and Event Handling
Presentation transcript:

Java Card Technology Ch06: Exception and Exception Handling Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Computer Science & Engineering Tatung University

Outline Exceptions in the java.lang Package Exceptions in the java.lang Package Java Card Exceptions Java Card Exceptions Java Card Exception Reason Code Java Card Exception Reason Code Throwing an Exception in the Java Card Platform Throwing an Exception in the Java Card Platform ISOException ISOException

Java Card Exceptions and Exception Handling An exception is an event that disrupts the normal flow of instructions during the execution of a program. An exception is an event that disrupts the normal flow of instructions during the execution of a program. Exceptions are important in the Java language Exceptions are important in the Java language  They provide an elegant way of handling errors in a platform.

Java Card Exceptions and Exception Handling A Java Card applet can use keywords throw, try, catch, or finally, and they work the same as in the Java platform. A Java Card applet can use keywords throw, try, catch, or finally, and they work the same as in the Java platform. Although the Java Card platform has full support for Java-style exceptions, there are differences in usage Although the Java Card platform has full support for Java-style exceptions, there are differences in usage  Due to the restrictive environment of smart card.

Exceptions in the java.lang The Java Card platform does not support all the exception types The Java Card platform does not support all the exception types  Because many of them are not applicable in a smart card context. Threads are not supported in the Java Card platform, and as a result, none of the thread- related exceptions are supported. Threads are not supported in the Java Card platform, and as a result, none of the thread- related exceptions are supported.

Exceptions in the java.lang (cont.) The class Throwable defines common ancestor for all the exception classes. The class Throwable defines common ancestor for all the exception classes. Applets can throw and catch only objects that derive from the Throwable class. Applets can throw and catch only objects that derive from the Throwable class.

Exceptions in the java.lang (cont.) The class Exception extends from the Throwable calss. It is the root class in the Java Card platform for all checked exceptions. The class Exception extends from the Throwable calss. It is the root class in the Java Card platform for all checked exceptions. The class RuntimeException derives from the Exception class, and it is the root class for all unchecked exceptions. The class RuntimeException derives from the Exception class, and it is the root class for all unchecked exceptions.

Exceptions in the java.lang (cont.) ThrowableExceptionRuntimeException Arithematic- Exception ArrayIndexOutOfB oundsException ArrayStoreException ArrayStoreException ClassCast- Exception IndexOutOfBound sException NullPointer-Exception Security- Exception NegativeArraySize Exception

Java Card Exceptions Checked exceptions are subclasses of the Exception class and must either be caught in the throwing method or be declared in a throws clause of the method header. Checked exceptions are subclasses of the Exception class and must either be caught in the throwing method or be declared in a throws clause of the method header.

Java Card Exceptions (cont.) All checked exceptions must eventually be caught by the applet All checked exceptions must eventually be caught by the applet  Checked exceptions indicate a programming error in an applet and thus should be corrected by the applet.  Checked exceptions are an important part of the interface to a method.

Java Card Exceptions (cont.) Unchecked exceptions (runtime exceptions) are subclasses of the class Runtime- Exception and need neither be caught in a program nor declared in a throws clause. Unchecked exceptions (runtime exceptions) are subclasses of the class Runtime- Exception and need neither be caught in a program nor declared in a throws clause. Unchecked exceptions typically indicate unexpected runtime problems—programming error or erroneous APDU processing state. Unchecked exceptions typically indicate unexpected runtime problems—programming error or erroneous APDU processing state.

Java Card Exceptions (cont.)

Why do we need the classes CardException and CardRuntime- Exception? Why do we need the classes CardException and CardRuntime- Exception?  Because they enable a resource- saving mechanism so that an exception object can be reused multiple times.

Java Card Exception Reason Code The Java exception classes supply a “message” string that indicates a specific error. The Java exception classes supply a “message” string that indicates a specific error. As an alternative way to attach extra information to the exception, the Java Card exception classes supply a numerical reason code. As an alternative way to attach extra information to the exception, the Java Card exception classes supply a numerical reason code.

Java Card Exception Reason Code (cont.) The reason code is used to describe optional details related to the throwing of the exception. The reason code is used to describe optional details related to the throwing of the exception. CardException and CardRuntimeExcep- tion define two public access methods CardException and CardRuntimeExcep- tion define two public access methods  GetReason and SetReason

Throwing an Exception in the Java Card Platform An applet creates an instance of an exception class, the code is written as follows An applet creates an instance of an exception class, the code is written as follows throw new MyException(“a specific error message”);

Throwing an Exception in the Java Card Platform (cont.) Space economy is always a concern in a smart card. Space economy is always a concern in a smart card. If an applet creates an object every time an exception is thrown, the applet will over time accumulate many unused exception instances in precious EEPROM memory. If an applet creates an object every time an exception is thrown, the applet will over time accumulate many unused exception instances in precious EEPROM memory.

Throwing an Exception in the Java Card Platform (cont.) To optimize memory usage, all exception objects should pre-created at initialization time and their references saved permanently. To optimize memory usage, all exception objects should pre-created at initialization time and their references saved permanently. When an exception event occurs, rather than creating a new exception object, an applet can do the following: When an exception event occurs, rather than creating a new exception object, an applet can do the following:  1. Retrieve and reuse the references for the desired exception object  2. Fill in the reason code in the object  3. Throw the object

Throwing an Exception in the Java Card Platform (cont.) CardException and CardRuntimeExcep- tion provide a static method throwIt for applets to reuse the exception instance CardException and CardRuntimeExcep- tion provide a static method throwIt for applets to reuse the exception instance public static void throwIt (short reason)

Throwing an Exception in the Java Card Platform (cont.) To reject an APDU command, an applet can throw an ISOException and indicate the reason code as “command not allowed”. To reject an APDU command, an applet can throw an ISOException and indicate the reason code as “command not allowed”. ISOException.throwIt(ISO7816.SW_COMMA ND_NOT_ALLOWED)

Throwing an Exception in the Java Card Platform (cont.) During initialization, the applet instantiates such an exception object and saves the reference in a persistent field. During initialization, the applet instantiates such an exception object and saves the reference in a persistent field.  The applet reuses the instance whenever it needs to throw that exception

ISOException ISOException is a special unchecked exception in the Java Card APIs. ISOException is a special unchecked exception in the Java Card APIs. ISOException encapsulates an ISO 7816 response status word (SW) in its reason code. ISOException encapsulates an ISO 7816 response status word (SW) in its reason code.

ISOException (cont.) The JCRE eventually catches an ISOException and returns the reason code it contains as an ISO status word to a host application. The JCRE eventually catches an ISOException and returns the reason code it contains as an ISO status word to a host application.  That’s why the exception class carries ISO in its name.

ISOException (cont.) The Java Card platform provides an interface javacard.framework.ISO7816 that defines the most commonly used status word constants The Java Card platform provides an interface javacard.framework.ISO7816 that defines the most commonly used status word constants  related to ISO and ISO