Fundaments of Game Design

Slides:



Advertisements
Similar presentations
Pearson Education, Inc. All rights reserved. 1.. Exception Handling.
Advertisements

Exceptions Chapter Throwing and Catching Exceptions When a program runs into a problem that it cannot handle, it throws an exception. Exceptions.
CSE 1302 Lecture 21 Exception Handling and Parallel Programming Richard Gesick.
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.
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
Review Linked list: Doubly linked list, insertback, insertbefore Remove Search.
 2006 Pearson Education, Inc. All rights reserved. Exception Handling in C++ CS-2303, C-Term Exception Handling in C++ CS-2303 System Programming.
Exception Handling Yaodong Bi Exception Handling Java exception handling Try blocks Throwing and re-throwing an exception Catching an.
Exception Handling 1 CISC6795, Spring Introduction 2 Exception – an indication of a problem that occurs during a program’s execution, for examples:
C++ Exception Handling
Understand Error Handling Software Development Fundamentals LESSON 1.4.
E XCEPTION H ANDLING Chapter 11 C S 442: A DVANCED J AVA P ROGRAMMING.
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and Exception Handling.
EXCEPTIONS Def: An exception is a run-time error. Examples include: attempting to divide by zero, or manipulate invalid data.
Exception Handling An Exception is an indication of a problem that occurs during a program’s execution. Exception handling enables the programmer to create.
Chapter 15 Strings String::Concat String::CompareTo, Equals, == If( string1 == S”Hello”) String1->Equals(S”Hello”) String1->CompareTo(S”Hello”) CompareTo.
 2002 Prentice Hall. All rights reserved Exception-Handling Overview Exception handling –improves program clarity and modifiability by removing.
 2009 Pearson Education, Inc. All rights reserved Exception Handling.
 2006 Pearson Education, Inc. All rights reserved Exception Handling.
Exception Handling  To use Try blocks to delimit code in which exceptions might occur.  To use Catch blocks to specify exception handlers.  To use the.
June 14, 2001Exception Handling in Java1 Richard S. Huntrods June 14, 2001 University of Calgary.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 9 : Exception Handling King Fahd University of Petroleum & Minerals College of Computer.
Dr. Abraham. Exception Any problem that VB or OS could not handle Robust program A program that performs well not only under ordinary conditions but also.
Object Oriented Programming
Java Programming Exceptions Handling. Topics: Learn about exceptions Try code and catch Exceptions Use the Exception getMessage() method Throw and catch.
CIS 270—Application Development II Chapter 13—Exception Handling.
Chapter 12: Exception Handling
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
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.
Sheet 3 HANDLING EXCEPTIONS Advanced Programming using Java By Nora Alaqeel.
Exceptions, handling exceptions & message boxes Year 11 Information Technology.
Exception Handling in C++. Outline What exceptions are and when to use them Using try, catch and throw to detect, handle and indicate exceptions, respectively.
Exceptions an unusual condition – e.g. division by zero – e.g. file doesn't exist – e.g. illegal type – etc. etc… typically a run-time error – i.e. during.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Lecture 18B Exception Handling and Richard Gesick.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
Eighth Lecture Exception Handling in Java
Appendix H Exception Handling: A Deeper Look
Exception handling.
Exception Handling in C++
Exceptions Error Handling and Recovery
16 Exception Handling.
Jim Fawcett CSE687-OnLine – Object Oriented Design Summer 2017
EXCEPTION HANDLING IN C++
Jim Fawcett CSE687 – Object Oriented Design Spring 2001
Java Programming Fifth Edition
Andy Wang Object Oriented Programming in C++ COP 3330
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
Why exception handling in C++?
Object Oriented Programming COP3330 / CGS5409
Exceptions C++ Interlude 3
Chapter 14: Exception Handling
YG - CS170.
Exception Handling and
EE422C Software Implementation II
Topics Introduction to File Input and Output
Andy Wang Object Oriented Programming in C++ COP 3330
Exception Handling Chapter 9 Edited by JJ.
Exception Handling.
Exception Handling In Text: Chapter 14.
Exception Handling Oo28.
Part B – Structured Exception Handling
Programming in C# CHAPTER - 7
Lecture 11 Objectives Learn what an exception is.
Exception and Event Handling
Topics Introduction to File Input and Output
Chapter 11: Exception Handling
CMSC 202 Exceptions.
Java Programming: From Problem Analysis to Program Design, 4e
More C++ Classes Systems Programming.
Presentation transcript:

Fundaments of Game Design Exception Handling Richard Gesick

Objectives Exception handling Try catch finally blocks Making it robust

Exception Handling An exception is an indication of a problem that occurs during a program’s execution. Exception handling enables applications to resolve exceptions. Exception handling enables clear, robust and more fault-tolerant programs. Exception handling helps improve a program’s fault tolerance.

Exception Handling Consider the following pseudocode: Perform a task If the preceding task did not execute correctly Perform error processing Perform next task If the preceding task did not execute correctly Perform error processing … In this pseudocode, we begin by performing a task; then we test whether that task executed correctly. If not, we perform error processing.

Exception Handling Exception handling enables programmers to remove error-handling code from the “main line” of the program’s execution. Programmers can decide to handle all exceptions, all exceptions of a certain type or all exceptions of related types. Such flexibility reduces the likelihood that errors will be overlooked.

try Block A try block encloses code that might throw exceptions and code that is skipped when an exception occurs. try {   open file   perform work on file  } close file

Catch Block When an exception occurs in a try block, a corresponding catch block catches the exception and handles it. At least one catch block must immediately follow a try block. A catch block specifies an exception parameter representing the exception that the catch block can handle. Optionally, you can include a catch block that does not specify an exception type to catch all exception types.

Catch Block catch(IO.FileNotFoundException fnfe) {   handle file not found (using fnfe object) } catch(Exception e) {   handle other type of exception (using e object)   close file }

Exception Handling- Termination Model When a method called in a program or the CLR detects a problem, the method or the CLR throws an exception. The point at which an exception occurs is called the throw point If an exception occurs in a try block, program control immediately transfers to the first catch block matching the type of the thrown exception. After the exception is handled, program control resumes after the last catch block.

finally Block Programs frequently request and release resources dynamically. Operating systems typically prevent more than one program from manipulating a file. Therefore, the program should close the file (i.e., release the resource) so other programs can use it. If the file is not closed, a resource leak occurs. The finally block is guaranteed to execute regardless of whether an exception occurs.

finally Block Local variables in a try block cannot be accessed in the corresponding finally block, so variables that must be accessed in both should be declared before the try block.

Reminder Do not place try blocks around every statement that might throw an exception. It’s better to place one try block around a significant portion of code, and follow this try block with catch blocks that handle each possible exception. Then follow the catch blocks with a single finally block. Separate try blocks should be used when it is important to distinguish between multiple statements that can throw the same exception type.

Expectations Within your games, you need to have robust exception handling for all of your file processing. If the file doesn’t exist or isn’t found, have a method for creating the file with default data and also for assigning that default data to the necessary components.

Expectations If there is a format or data content error, have a process to handle that keeps the game from throwing an exception in the editor.

Unity If you are using multiple scenes, when your file processing is in the scene that uses the data and the file isn’t found, Unity may not wait for you to handle the exception/create the file. It may throw an exception and move on without the data if it can. Consider testing for the file’s existence in the opening scene of your game. Causes:???

File checker script attached to camera void Start () { if(!File.Exists(Application.persistentDataPath + "\\" + "scoreFile.txt")) { Debug.Log("creating score file in file checker"); StreamWriter sw = new StreamWriter(Application.persistentDataPath + "\\" + "scoreFile.txt"); sw.WriteLine("A 9"); . . . sw.WriteLine("E 5"); sw.Close(); }