ASPError オブジェクト | |
ASP 3.0 で導入された組み込み型の ASPError オブジェクトを使用すると、現在のセッションの ASP ページのスクリプトで発生した最後のエラーに関する詳細な情報を表示できます。このオブジェクトは、9 つの読み取り専用プロパティを介して、エラーのタイプとソースに関する詳細な情報を提供します。この情報は、VBScript の Err オブジェクトから得られる情報よりも詳細です。 ASPError オブジェクトとそのプロパティを使用するには、Server オブジェクトの新しいメソッド GetLastError を呼び出す必要があります。このメソッドは、ASPErrorObject を返します。このオブジェクトのプロパティの値は、次に示すように、スクリプト内で発生した最後のエラーに関する詳細を反映するように設定されています。 Dim objMyASPError Set objMyASPError = Server.GetLastError IIS 5.0 をインストールした場合、デフォルトでは、ASP コードで何らかの前処理、スクリプト、ランタイムのエラーが発生すると、IIS では、現在のスクリプトの処理を停止し、スクリプトの実行を デフォルトのエラーページ ASPError オブジェクトのプロパティ、コレクション、メソッド、およびイベントの概要については、次のボックスを参照してください。 |
コメントおよびトラブルシューティング | |
初心者の ASP デベロッパーの多くは、次のコードを使用して、VBScript の Err オブジェクトを使用したスクリプトのデバッグを有効にします。 On Error Resume Next スクリプトにこのコード行を指定すると、前処理エラーとスクリプト (構文) エラーが発生した場合にのみ、IIS は Server.Transfer メソッドを呼び出し、スクリプトの実行を Dim intCounter For intCounter = 1 to 100 intResult = intCounter / (intCounter - 100) Next このスニペットでは、intCounter が 100 になると発生する 0 による除算エラーを捕捉するコードを、Next ステートメントの前に追加する必要があります。エラー捕捉用のこれらの行をコード全体に渡って追加する場合は、エラー発生の可能性がある行を予期して効率的にトラップする必要があるため、処理時間がかかり、それ自体エラーを起こしやすい状態になります。このことから、および ASPError オブジェクトから得られる情報が Err オブジェクトより多いことから、On Error Resume Next はできる限り使用しないようにしてください。 ASPError オブジェクトページの もう 1 つ考えられる方法は、 ASPError オブジェクトのプロパティを例示する次のコード例ではすべて、3 つの異なるエラー生成スクリプトを活用しています。最初のスクリプトには構文エラーがあり、2 番目のスクリプトには前処理ディレクティブにエラーがあります。3 番目のスクリプトではランタイムエラーが生成されます。これらの例ではすべて同じ 3 つの ASP ページを活用してエラーを生成していますが、カスタムエラーページ **** BEGIN Error Generating Script #1 **** <HTML> <HEAD><TITLE> Error Generation Page #1 </TITLE></HEAD> <BODY> <% ' This page contains a syntax error. ' In the following For...Next loop, the keyword ' "For" is mispelled. Dim intCounter Fir intCounter = 1 to 100 %> Look everyone! I'm counting: <%=intCounter%><BR> <% Next %> </BODY> </HTML> **** END Error Generating Script #1 **** **** BEGIN Error Generating Script #2 **** <HTML> <HEAD><TITLE> Error Generation Page #2 </TITLE></HEAD> <BODY> <% ' This page contains a preprocessing error. ' The work "file" in the #INCLUDE preprocessor ' directive is mispelled: %> <!--#include fil=/headers/AdminHeader.INC --> </BODY> </HTML> **** END Error Generating Script #2 **** **** BEGIN Error Generating Script #3 **** <HTML> <HEAD><TITLE> Error Generation Page #3 </TITLE></HEAD> <BODY> <% ' This page contains a runtime error. ' In the following For...Next loop, when the ' intCounter variable gets to zero, the result ' is a divide by zero error. Dim intCounter Dim dblDivResult For intCounter = 1 to 100 dblDivResult = intCounter / (intCounter - 100) %> Look everyone! I'm dividing: <%=dblDivResult%><BR> <% Next %> </BODY> </HTML> **** END Error Generating Script #3 **** |
ASPCode | |
objASPError.ASPCode | |
The ASPCode プロパティは、エラーを生成したスクリプトで発生した ASP 固有のエラーを表す数値コードを保持します。ASP スクリプトの処理でエラーが発生した場合、IIS によってこのプロパティが書き込まれます。 ASPCode プロパティは読み取り専用です。 |
|
パラメータ | |
なし |
|
例 | |
この例では、デフォルトのカスタムエラースクリプト **** BEGIN ASPCode Example Script **** <% ' This script demonstrates the use of the ASPCode ' property of the ASPError object. Dim objMyASPError Set objMyASPError = Server.GetLastError( ) Response.Write "The value of the ASPCode property is " & objMyASPError.ASPCode %> **** END ASPCode Example Script **** エラー生成スクリプトを実行すると、前のスクリプト例では、次の 3 つの応答が生成されます。 エラー生成スクリプト #1: The value of the ASPCode property is [EMPTY] エラー生成スクリプト #2: The value of the ASPCode property is ASP 0128 エラー生成スクリプト #3: The value of the ASPCode property is [EMPTY] |
|
メモ | |
前にも説明したように、ASP スクリプト自身の解釈時にエラーが発生しない限り、ASPCode プロパティは書き込まれません。このことは、すべての前処理ディレクティブに当てはまります。 |
|
ASPDescription | |
objASPError.ASPDescription | |
ASPDescription プロパティは、ASP エラーの発生時に IIS によって書き込まれる文字列値です。このプロパティからは、発生した ASP エラーのタイプに関して、ASPCode プロパティよりも記述的なデータが得られます。ASPDescription プロパティは、ASPCode プロパティと同様に、発生したエラーがランタイムエラーの結果ではなく ASP スクリプトの解釈時のエラーである場合にのみ書き込まれます。 |
|
パラメータ | |
なし |
|
例 | |
この例では、「コメントおよびトラブルシューティング」の最後に列挙したエラー生成スクリプトを使用しています。デフォルトのカスタムエラースクリプト **** BEGIN ASPDescription Example Script **** <% ' This script demonstrates the use of the ASPDescription ' property of the ASPError object. Dim objMyASPError Set objMyASPError = Server.GetLastError( ) Response.Write "The value of the ASPDescription property is " & _ objMyASPError.ASPDescription %> **** END ASPDescription Example Script **** エラー生成スクリプトを実行すると、前の ASPDescription スクリプトでは、次の 3 つの応答が生成されます。 エラー生成スクリプト #1: The value of the ASPDescription property is [EMPTY] エラー生成スクリプト #2: The value of the ASPDescription property is The Include file name must be specified using either the File or Virtual attribute. エラー生成スクリプト #3: The value of the ASPDescription property is [EMPTY] |
|
メモ | |
ASPDescription プロパティは、ASPCode プロパティと同様に、ASP 解釈時固有のエラーにのみ役立ちます。ASPError オブジェクトの Description プロパティは、ほぼ必ず、最新のエラーについて同程度かまたはより適切な情報を提供します。 |
|
Category | |
objASPError.Category | |
Category プロパティは、IIS-specific、scripting language specific、component specific など、発生したエラーのタイプを示す文字列を保持します。 |
|
パラメータ | |
なし |
|
例 | |
この例では、「コメントおよびトラブルシューティング」の最後に列挙したエラー生成スクリプトを使用しています。デフォルトのカスタムエラースクリプト **** BEGIN Category Example Script **** <% ' This script demonstrates the use of the Category ' property of the ASPError object. Dim objMyASPError Set objMyASPError = Server.GetLastError( ) Response.Write "The value of the Category property is " & objMyASPError.Category %> **** END Category Example Script **** エラー生成スクリプトを実行すると、このスクリプトでは、次の 3 つの応答が生成されます。 エラー生成スクリプト #1: The value of the Category property is Microsoft VBScript compilation エラー生成スクリプト #2: The value of the Category property is Active Server Pages エラー生成スクリプト #3: The value of the Category property is Microsoft VBScript runtime |
|
メモ | |
Category プロパティを使用すると、エラーの検索場所を絞り込むことができます。 |
|
Column | |
objASPError.Column | |
Column プロパティは、エラーの原因となったコードの最初の文字を含む文字の指定列を示す long 型の値を保持します。 |
|
パラメータ | |
なし |
|
例 | |
この例では、「コメントおよびトラブルシューティング」の最後に列挙したエラー生成スクリプトを使用しています。デフォルトのカスタムエラースクリプト **** BEGIN Column Example Script **** <% ' This script demonstrates the use of the Column ' property of the ASPError object. Dim objMyASPError Set objMyASPError = Server.GetLastError( ) Response.Write "The value of the Column property is " & objMyASPError.Column %> **** END Column Example Script **** エラー生成スクリプトを実行すると、前の Column スクリプトでは、次の 3 つの応答が生成されます。 エラー生成スクリプト #1: The value of the Column property is 19 エラー生成スクリプト #2: The value of the Column property is -1 エラー生成スクリプト #3: The value of the Column property is -1 |
|
メモ | |
Column プロパティは、コード内の構文エラーを調べる際に便利です。ただし、エラーが ASP 固有のエラーである場合またはエラーの発生場所に構文上不正なコードがない場合、この値は -1 となり用途が限定されます。 |
|
Description | |
objASPError.Description | |
Description プロパティは、最後に発生したエラーを記述する文字列です。これは通常、ASP 解釈時固有のエラーである点を除けば、関連する ASPDescription プロパティよりも記述的で便利です。 |
|
パラメータ | |
なし |
|
例 | |
この例では、「コメントおよびトラブルシューティング」の最後に列挙したエラー生成スクリプトを使用しています。デフォルトのカスタムエラースクリプト **** BEGIN Description Example Script **** <% ' This script demonstrates the use of the Description ' property of the ASPError object. Dim objMyASPError Set objMyASPError = Server.GetLastError( ) Response.Write "The value of the Description property is " & objMyASPError.Description %> **** END Description Example Script **** エラー生成スクリプトを実行すると、前の Description スクリプトでは、次の 3 つの応答が生成されます。 エラー生成スクリプト #1: The value of the Description property is Expected end of statement エラー生成スクリプト #2: The value of the Description property is Missing File or Virtual attribute エラー生成スクリプト #3: The value of the Description property is Division by zero |
|
メモ | |
Description プロパティの値は、一般的に ASPError オブジェクトの他のプロパティより記述的です。ただし、他のすべてのプロパティと同様に、ASP アプリケーションのエンドユーザーにとって、その用途は著しく限定されます。このため、エラーの原因を説明する表示情報は、ユーザーにとって有益で役立ちます。この章の最後に、カスタマイズされた |
|
File | |
objASPError.File | |
File プロパティには、エラーを生成したコードを含むファイルへの完全パスがあります。このファイル名には、Web ルートからファイルへの完全パスが含まれています。 |
|
パラメータ | |
なし |
|
例 | |
この例では、「コメントおよびトラブルシューティング」の最後に列挙したエラー生成スクリプトを使用しています。デフォルトのカスタムエラースクリプト **** BEGIN File Example Script **** <% ' This script demonstrates the use of the File ' property of the ASPError object. Dim objMyASPError Set objMyASPError = Server.GetLastError( ) Response.Write "The value of the File property is " & objMyASPError.File %> **** END File Example Script **** エラー生成スクリプトを実行すると、前の File スクリプトでは、次の 3 つの応答が生成されます。 エラー生成スクリプト #1: The value of the File property is /errorgen1.asp エラー生成スクリプト #2: The value of the File property is /errorgen2.asp エラー生成スクリプト #3: The value of the File property is /errorgen3.asp |
|
メモ | |
ファイルのパスは、Web サーバーのルートパスから記載されています。現在のアプリケーションのルートからのパスではありません。 |
|
Line | |
objASPError.Line | |
Line プロパティは、エラーを生成したコードが出現する行番号を表す long 型の値です。 |
|
パラメータ | |
なし |
|
例 | |
この例では、「コメントおよびトラブルシューティング」の最後に列挙したエラー生成スクリプトを使用しています。デフォルトのカスタムエラースクリプト **** BEGIN Line Example Script **** <% ' This script demonstrates the use of the Line ' property of the ASPError object. Dim objMyASPError Set objMyASPError = Server.GetLastError( ) Response.Write "The value of the Line property is " & objMyASPError.Line %> **** END Line Example Script **** エラー生成スクリプトを実行すると、前の Line スクリプトでは、次の 3 つの応答が生成されます。 エラー生成スクリプト #1: The value of the Line property is 11 エラー生成スクリプト #2: The value of the Line property is 11 エラー生成スクリプト #3: The value of the Line property is 14 |
|
メモ | |
行のカウントは、コードの先頭の ASP 行を 1 として始まります。 |
|
Number | |
objASPError.Number | |
Number プロパティには、COM コンポーネントから返されたエラーコードを表す long 型の値が含まれています。この long 型の値は、標準の COM エラーコードとなります。 |
|
パラメータ | |
なし |
|
例 | |
この例では、「コメントおよびトラブルシューティング」の最後に列挙したエラー生成スクリプトを使用しています。デフォルトのカスタムエラースクリプト **** BEGIN Number Example Script **** <% ' This script demonstrates the use of the Number ' property of the ASPError object. Dim objMyASPError Set objMyASPError = Server.GetLastError( ) Response.Write "The value of the Number property is " & objMyASPError.Number %> **** END Number Example Script **** エラー生成スクリプトを実行すると、次の 3 つの応答が生成されます。 エラー生成スクリプト #1: The value of the Number property is -2146827263 エラー生成スクリプト #2: The value of the Number property is -2147467259 エラー生成スクリプト #3: The value of the Number property is -2146828277 |
|
メモ | |
なし |
|
Source | |
objASPError.Source | |
Source プロパティは、最後のエラーの原因となったコードが構文的に不正であった場合に、そのコード行を含む文字列です。 |
|
パラメータ | |
なし |
|
例 | |
この例では、「コメントおよびトラブルシューティング」の最後に列挙したエラー生成スクリプトを使用しています。デフォルトのカスタムエラースクリプト **** BEGIN Source Example Script **** <% ' This script demonstrates the use of the Source ' property of the ASPError object. Dim objMyASPError Set objMyASPError = Server.GetLastError( ) Response.Write "The value of the Source property is " & objMyASPError.Source %> **** END Source Example Script **** エラー生成スクリプトを実行すると、前の Source スクリプトでは、次の 3 つの応答が生成されます。 エラー生成スクリプト #1: The value of the Source property is Fir intCounter = 1 to 100 エラー生成スクリプト #2: The value of the Source property is [EMPTY] エラー生成スクリプト #3: The value of the Source property is [EMPTY] |
|
メモ | |
前にも説明したように、Source プロパティは、生成されたエラーが構文に関連している場合にのみ役立ちます。構文に関連するエラーでない場合、このプロパティは空です。 |
|