パッケージトップレベル
public dynamic class Error
継承Error Inheritance Object
SubclassesArgumentError, AutomationError, CollectionViewError, CursorError, DataListError, DataServiceError, DefinitionError, EvalError, Fault, IllegalOperationError, InvalidCategoryError, InvalidFilterError, InvalidSWFError, IOError, ItemPendingError, MemoryError, MessagingError, NoDataAvailableError, RangeError, ReferenceError, ScriptTimeoutError, SecurityError, SortError, StackOverflowError, SyntaxError, TypeError, UnresolvedConflictsError, URIError, VerifyError, VideoError

Error クラスには、スクリプトで発生したエラーに関する情報が含まれています。ActionScript 3.0 アプリケーションの開発において、コンパイルされたコードを Flash Player のデバッグ版で実行すると、Error 型またはサブクラスの例外がダイアログボックスに表示されるため、コードのトラブルシューティングに役立ちます。Error オブジェクトを作成するには、Error コンストラクタ関数を使用します。一般には、try コードブロック内から新しい Error オブジェクトをスローします。そして、catch コードブロックまたは finally コードブロックでこれをキャッチします。

Error クラスのサブクラスを作成し、そのクラスのインスタンスをスローすることもできます。

例の表示

関連項目

デバッグ版の Flash Player の操作
カスタムエラークラスの作成
エラーイベントおよびステータスへの応答


パブリックプロパティ
 プロパティ定義
 Inheritedconstructor : Object
指定されたオブジェクトインスタンスのクラスオブジェクトまたはコンストラクタ関数への参照です。
Object
  errorID : int
[read-only] 特定のエラーメッセージに関連付けられた参照番号です。
Error
  message : String
Error オブジェクトに関連付けられたメッセージです。
Error
  name : String
Error オブジェクトの名前です。
Error
 Inheritedprototype : Object
[static] クラスまたは関数オブジェクトのプロトタイプオブジェクトへの参照です。
Object
パブリック Methods
 メソッド定義
  
Error(message:String = "", id:int = 0)
新しい Error オブジェクトを作成します。
Error
  
エラーの構築時にエラーの呼び出しスタックをストリングで返します (デバッガバージョンの Flash Player のみ)。
Error
 Inherited
指定されたプロパティがオブジェクトに定義されているかどうかを示します。
Object
 Inherited
Object クラスのインスタンスが、パラメータとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。
Object
 Inherited
指定されたプロパティが存在し、列挙できるかどうかを示します。
Object
 Inherited
ループ処理に対するダイナミックプロパティの可用性を設定します。
Object
  
デフォルトでは "Error" というストリングを返します。Error.message プロパティが定義されている場合は、その値を返します。
Error
 Inherited
指定されたオブジェクトのプリミティブな値を返します。
Object
プロパティの詳細
errorIDプロパティ
errorID:int  [read-only]

特定のエラーメッセージに関連付けられた参照番号です。カスタム Error オブジェクトの場合、この番号はコンストラクタで提供される id パラメータの値です。

実装
    public function get errorID():int
messageプロパティ 
public var message:String

Error オブジェクトに関連付けられたメッセージです。デフォルトでは、このプロパティの値は "Error" です。Error オブジェクトを作成する際に、Error コンストラクタ関数にエラーストリングを渡すことで message プロパティを指定できます。

関連項目

nameプロパティ 
public var name:String

Error オブジェクトの名前です。デフォルトでは、このプロパティの値は "Error" です。

関連項目

コンストラクタの詳細
Error()コンストラクタ
public 関数 Error(message:String = "", id:int = 0)

新しい Error オブジェクトを作成します。message を指定した場合は、その値がオブジェクトの Error.message プロパティに割り当てられます。

パラメータ
message:String (default = "") — Error オブジェクトに関連付けられたストリング。このパラメータはオプションです。
 
id:int (default = 0) — 特定のエラーメッセージに関連付ける参照番号です。

関連項目



The following example creates a new Error object err and then, using the Error() constructor, assigns the string "New Error Message" to err.

var err:Error = new Error(); trace(err.toString());    // Error

err = new Error("New Error Message"); trace(err.toString());    // Error: New Error Message

メソッドの詳細
getStackTrace()メソッド
public function getStackTrace():String

エラーの構築時にエラーの呼び出しスタックをストリングで返します (デバッガバージョンの Flash Player のみ)。次の例に示されているように、戻り値の先頭行は、例外オブジェクトのストリング表現で、その後にはスタックトレースエレメントが続きます。

  TypeError: null cannot be converted to an object
      at com.xyz.OrderEntry.retrieveData(OrderEntry.as:995)
      at com.xyz.OrderEntry.init(OrderEntry.as:200)
      at com.xyz.OrderEntry.$construct(OrderEntry.as:148)
     

戻り値
String — 呼び出しスタックのストリング表現です。
toString()メソッド 
public override function toString():String

デフォルトでは "Error" というストリングを返します。Error.message プロパティが定義されている場合は、その値を返します。

戻り値
String — エラーメッセージです。

関連項目



The following example creates a new Error object err and then, using the Error() constructor, assigns the string "New Error Message" to err. Finally, the message property is set to "Another New Error Message", which overwrites "New Error Message".

var err:Error = new Error(); trace(err.toString());    // Error

err = new Error("New Error Message"); trace(err.toString());    // Error: New Error Message

err.message = "Another New Error Message"; trace(err.toString());    // Error: Another New Error Message


The following example uses the ErrorExample class to show how a custom error can be generated. This is accomplished with the following steps:
  1. A local variable nullArray of Array type is declared, but notice that a new Array object is never created.
  2. The constructor attempts to load a value into the uninitialized array by using the push() method within an error handling code segment that catches a custom error by using the CustomError class, which extends Error.
  3. When the CustomError is thrown, the constructor catches it and then outputs an error message by using the trace() statement.
 package { import flash.display.Sprite; public class ErrorExample extends Sprite { private var nullArray:Array; public function ErrorExample() { try { nullArray.push("item"); } catch(e:Error) { throw new CustomError("nullArray is null"); } } } }

class CustomError extends Error { public function CustomError(message:String) { super(message); } }