次の方法で共有


TypeLoadException コンストラクタ (String, Exception)

指定したエラー メッセージと、この例外の原因である内部例外への参照を使用して、TypeLoadException クラスの新しいインスタンスを初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)

構文

'宣言
Public Sub New ( _
    message As String, _
    inner As Exception _
)
'使用
Dim message As String
Dim inner As Exception

Dim instance As New TypeLoadException(message, inner)
public TypeLoadException (
    string message,
    Exception inner
)
public:
TypeLoadException (
    String^ message, 
    Exception^ inner
)
public TypeLoadException (
    String message, 
    Exception inner
)
public function TypeLoadException (
    message : String, 
    inner : Exception
)

パラメータ

  • message
    例外の原因を説明するエラー メッセージ。
  • inner
    現在の例外の原因である例外。inner パラメータが null 参照 (Visual Basic の場合は Nothing) でない場合は、内部例外を処理する catch ブロックで現在の例外が発生します。

解説

前の例外の直接の結果としてスローされる例外については、InnerException プロパティに、前の例外への参照が格納されます。InnerException プロパティは、コンストラクタに渡されたものと同じ値を返します。InnerException プロパティによって内部例外値がコンストラクタに渡されなかった場合は、null 参照 (Visual Basic の場合は Nothing) を返します。

TypeLoadException のインスタンスの初期プロパティ値を次の表に示します。

プロパティ

InnerException

内部例外参照。

Message

エラー メッセージ文字列。

使用例

Imports System
Imports System.Runtime.InteropServices

Public Class TypeLoadException_Constructor3
   Public Shared Sub Main()
      Console.WriteLine("Calling a method in a non-existent DLL which triggers a TypeLoadException.")
      Try
         TypeLoadExceptionDemoClass.GenerateException()
      Catch e As TypeLoadException
         Console.WriteLine(("TypeLoadException: " + ControlChars.Cr + ControlChars.Tab + "Error Message = " + e.Message))
         Console.WriteLine(("TypeLoadException: " + ControlChars.Cr + ControlChars.Tab + "InnerException Message = " + e.InnerException.Message))
      Catch e As Exception
         Console.WriteLine(("Exception: " + ControlChars.Cr + ControlChars.Tab + "Error Message = " + e.Message))
      End Try
   End Sub 'Main
End Class 'TypeLoadException_Constructor3

Class TypeLoadExceptionDemoClass
   ' A call to this method will raise a TypeLoadException.
   Public Declare Sub NonExistentMethod Lib "NonExistentDLL.DLL" Alias "MethodNotExists" ()

   Public Shared Sub GenerateException()
      Try
         NonExistentMethod()
      Catch e As TypeLoadException
         ' Rethrow exception with the exception as inner exception
         Throw New TypeLoadException("This exception was raised due to a call to an invalid method.", e)
      End Try
   End Sub 'GenerateException
End Class 'TypeLoadExceptionDemoClass
using System;
using System.Runtime.InteropServices;

public class TypeLoadException_Constructor3
{
   public static void Main() 
   {
      Console.WriteLine("Calling a method in a non-existent DLL which triggers a TypeLoadException.");
      try 
      {
         TypeLoadExceptionDemoClass.GenerateException();
      }  
      catch (TypeLoadException e)
      {
         Console.WriteLine ("TypeLoadException: \n\tError Message = " + e.Message);
         Console.WriteLine ("TypeLoadException: \n\tInnerException Message = " + e.InnerException.Message );
      }  
      catch (Exception e)
      {
         Console.WriteLine ("Exception: \n\tError Message = " + e.Message);
      }
   }
}

class TypeLoadExceptionDemoClass
{ 
   // A call to this method will raise a TypeLoadException.
   [DllImport("NonExistentDLL.DLL", EntryPoint="MethodNotExists")]
   public static extern void NonExistentMethod();

   public static void GenerateException() 
   {
      try 
      {
         NonExistentMethod();
      }
      catch (TypeLoadException e) 
      {
         // Rethrow exception with the exception as inner exception
         throw new TypeLoadException("This exception was raised due to a call to an invalid method.", e);
      }
   }
}
using namespace System;
using namespace System::Runtime::InteropServices;
ref class TypeLoadExceptionDemoClass
{
public:

   // A call to this method will raise a TypeLoadException.

   [DllImport("NonExistentDLL.DLL",EntryPoint="MethodNotExists")]
   static void NonExistentMethod();
   static void GenerateException()
   {
      try
      {
         NonExistentMethod();
      }
      catch ( TypeLoadException^ e ) 
      {
         
         // Rethrow exception with the exception as inner exception
         throw gcnew TypeLoadException( "This exception was raised due to a call to an invalid method.",e );
      }

   }

};

int main()
{
   Console::WriteLine( "Calling a method in a non-existent DLL which triggers a TypeLoadException." );
   try
   {
      TypeLoadExceptionDemoClass::GenerateException();
   }
   catch ( TypeLoadException^ e ) 
   {
      Console::WriteLine( "TypeLoadException: \n\tError Message = {0}", e->Message );
      Console::WriteLine( "TypeLoadException: \n\tInnerException Message = {0}", e->InnerException->Message );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception: \n\tError Message = {0}", e->Message );
   }

}
import System.*;
import System.Runtime.InteropServices.*;

public class TypeLoadException_Constructor3
{
    public static void main(String[] args)
    {
        Console.WriteLine("Calling a method in a non-existent DLL which"
            +" triggers a TypeLoadException.");
        try {
            TypeLoadExceptionDemoClass.GenerateException();
        }
        catch (TypeLoadException e) {
            Console.WriteLine("TypeLoadException: \n\tError Message = " 
                + e.get_Message());
            Console.WriteLine("TypeLoadException: \n\tInnerException Message = "
                + e.get_InnerException().get_Message());
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception: \n\tError Message = "
                + e.get_Message());
        }
    } //main
} //TypeLoadException_Constructor3

class TypeLoadExceptionDemoClass
{
    // A call to this method will raise a TypeLoadException.
    /** @attribute DllImport("NonExistentDLL.DLL", EntryPoint = 
        "MethodNotExists")
     */
    public static native void NonExistentMethod();

    public static void GenerateException()
    {
        try {
            NonExistentMethod();
        }
        catch (TypeLoadException e) {
            // Rethrow exception with the exception as inner exception
            throw new TypeLoadException("This exception was raised due to a "
                +"call to an invalid method.", e);
        }
    } //GenerateException
} //TypeLoadExceptionDemoClass

プラットフォーム

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 2.0、1.0

参照

関連項目

TypeLoadException クラス
TypeLoadException メンバ
System 名前空間
Exception クラス

その他の技術情報

例外の処理とスロー