IOExceptionとは? わかりやすく解説

IOException クラス

I/O エラーが発生したときにスローされる例外。

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

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class IOException
    Inherits SystemException
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class IOException : SystemException
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class IOException : public
 SystemException
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class IOException extends SystemException
SerializableAttribute 
ComVisibleAttribute(true) 
public class IOException extends
 SystemException
解説解説

IOException は、ストリーム、ファイル、およびディレクトリを使用して情報にアクセスするときにスローされる例外の基本クラスです。

基本クラス ライブラリには、次の型が含まれています。それぞれの型は、IOException の派生クラスです。

  • DirectoryNotFoundException

  • EndOfStreamException

  • FileNotFoundException

  • FileLoadException

  • PathTooLongException

該当する場合は、IOException ではなくここで示した型を使用してください。

IOException は、値 0x80131620 の HRESULT COR_E_IO を使用します。

使用例使用例

次のコード例は FileStream.Lock メソッドの例の一部です。

' Catch the IOException generated if the 
' specified part of the file is locked.
Catch ex As IOException
    Console.WriteLine( _
        "{0}: The write operation could " & _
        "not be performed because the " & _
        "specified part of the file is " & _
        "locked.", ex.GetType().Name)
End Try
// Catch the IOException generated if the 
// specified part of the file is locked.
catch(IOException e)
{
    Console.WriteLine(
        "{0}: The write operation could not " +
        "be performed because the specified " +
        "part of the file is locked.", 
        e.GetType().Name);
}
// Catch the IOException generated if the 
// specified part of the file is locked.
catch ( IOException^ e ) 
{
   Console::WriteLine( "{0}: The write operation could not "
   "be performed because the specified "
   "part of the file is locked.", e->GetType()->Name );
}


// Catch the IOException generated if the 
// specified part of the file is locked.
catch(IOException e) {                        
    Console.WriteLine(
        "{0}: The write operation could not "
        + "be performed because the specified "
        + "part of the file is locked.", 
        e.GetType().get_Name());
}
継承階層継承階層
System.Object
   System.Exception
     System.SystemException
      System.IO.IOException
         派生クラス
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IOException コンストラクタ ()

メッセージ文字列を空の文字列 ("") に設定し、HRESULT を COR_E_IO に設定し、内部例外を null 参照に設定して、IOException クラスの新しいインスタンスを初期化します。

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

public IOException ()
public:
IOException ()
public IOException ()
解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IOException コンストラクタ (String, Int32)

メッセージ文字列を message に設定し、HRESULT をユーザー定義に設定して、IOException クラスの新しいインスタンスを初期化します。

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

Public Sub New ( _
    message As String, _
    hresult As Integer _
)
Dim message As String
Dim hresult As Integer

Dim instance As New IOException(message,
 hresult)
public IOException (
    string message,
    int hresult
)
public:
IOException (
    String^ message, 
    int hresult
)
public IOException (
    String message, 
    int hresult
)
public function IOException (
    message : String, 
    hresult : int
)

パラメータ

message

エラーを説明する String。message の内容は、ユーザーが理解できる内容にします。このコンストラクタの呼び出し元は、この文字列が現在のシステムのカルチャに合わせてローカライズ済みであることを確認しておく必要があります。

hresult

発生したエラーを識別する整数。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

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

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

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

Public Sub New ( _
    message As String, _
    innerException As Exception _
)
Dim message As String
Dim innerException As Exception

Dim instance As New IOException(message,
 innerException)
public IOException (
    string message,
    Exception innerException
)
public:
IOException (
    String^ message, 
    Exception^ innerException
)
public IOException (
    String message, 
    Exception innerException
)
public function IOException (
    message : String, 
    innerException : Exception
)

パラメータ

message

例外の原因を説明するエラー メッセージ。

innerException

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

解説解説

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

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

内部例外の詳細については、InnerException のトピックを参照してください。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IOException コンストラクタ (SerializationInfo, StreamingContext)

指定したシリアル化情報とコンテキスト情報を使用して、IOException クラスの新しいインスタンスを初期化します。

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

Protected Sub New ( _
    info As SerializationInfo, _
    context As StreamingContext _
)
Dim info As SerializationInfo
Dim context As StreamingContext

Dim instance As New IOException(info,
 context)
protected IOException (
    SerializationInfo info,
    StreamingContext context
)
protected:
IOException (
    SerializationInfo^ info, 
    StreamingContext context
)
protected IOException (
    SerializationInfo info, 
    StreamingContext context
)
protected function IOException (
    info : SerializationInfo, 
    context : StreamingContext
)

パラメータ

info

オブジェクトをシリアル化または逆シリアル化するためのデータ。

context

オブジェクトのソースとデスティネーション。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IOException コンストラクタ

メッセージ文字列を設定して、IOException クラスのインスタンスを初期化します。
オーバーロードの一覧オーバーロードの一覧

参照参照

IOException コンストラクタ (String)

メッセージ文字列を message に設定し、HRESULT を COR_E_IO に設定し、内部例外を null 参照 (Visual Basic では Nothing) に設定して、IOException クラスの新しいインスタンスを初期化します。

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

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IOException プロパティ


パブリック プロパティパブリック プロパティ

プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HResult  特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。 ( Exception から継承されます。)
参照参照

IOException メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

IOException メンバ

I/O エラーが発生したときにスローされる例外。

IOException データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
プロテクト コンストラクタプロテクト コンストラクタ
パブリック プロパティパブリック プロパティ
プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HResult  特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。(Exception から継承されます。)
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「IOException」の関連用語

IOExceptionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



IOExceptionのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS