Skip to Main Content
Essential ActionScript 3.0
book

Essential ActionScript 3.0

by Colin Moock
June 2007
Intermediate to advanced content levelIntermediate to advanced
948 pages
27h 2m
English
O'Reilly Media, Inc.
Content preview from Essential ActionScript 3.0

Chapter 13. Exceptions and Error Handling

In this chapter, we’ll explore ActionScript’s system for generating and responding to runtime errors—or exceptions. In ActionScript, errors can be generated both by the Flash runtime and by the program that is executing. Errors generated by the Flash runtime are known as built-in errors; errors generated by a program are known as custom errors. In a program, we can respond to, or handle, any error (whether built-in or custom) using the try/catch/finally statement; we can generate an error via the throw statement.

To learn how to generate and respond to errors in a program, we’ll revisit our virtual zoo program.

Tip

This chapter’s updates to the virtual zoo program are the last we’ll make until the end of this book. To complete the virtual zoo program we must discuss display programming and mouse input, both of which are covered in Part II. After you read Part II, consult the "Appendix A,” (Appendix) to see how to add graphics and interactivity to the virtual zoo program.

The Exception-Handling Cycle

Recall that the VirtualPet class defines a setName( ) method that sets the petName variable of VirtualPet instances. As a refresher, here’s the relevant VirtualPet class code (portions of the class that do not pertain to setting the petName variable are omitted):

public class VirtualPet { private var petName:String; public function setName (newName:String):void { // If the proposed new name has more than maxNameLength characters... if (newName.length ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Essential ActionScript 2.0

Essential ActionScript 2.0

Colin Moock
The ActionScript 3.0 Quick Reference Guide

The ActionScript 3.0 Quick Reference Guide

Jen deHaan, David Stiller, Darren Richardson, Rich Shupe
ActionScript 3.0 Cookbook

ActionScript 3.0 Cookbook

Joey Lott, Darron Schall, Keith Peters

Publisher Resources

ISBN: 0596526946Errata