EndOfStreamException クラス

定義

ストリームの末尾を越えて読み取りを試行するとスローされる例外。

public ref class EndOfStreamException : System::IO::IOException
public class EndOfStreamException : System.IO.IOException
[System.Serializable]
public class EndOfStreamException : System.IO.IOException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class EndOfStreamException : System.IO.IOException
type EndOfStreamException = class
    inherit IOException
[<System.Serializable>]
type EndOfStreamException = class
    inherit IOException
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type EndOfStreamException = class
    inherit IOException
Public Class EndOfStreamException
Inherits IOException
継承
EndOfStreamException
継承
属性

次のコード例は、MemoryStream クラスの上にある BinaryReader クラスと BinaryWriter クラスを使用して、Double データをメモリに読み書きする方法を示しています。

using System;
using System.IO;

class BinaryRW
{
    static void Main()
    {
        int i;
        const int arrayLength = 1000;

        // Create random data to write to the stream.
        Random randomGenerator = new Random();
        double[] dataArray = new double[arrayLength];
        for(i = 0; i < arrayLength; i++)
        {
            dataArray[i] = 100.1 * randomGenerator.NextDouble();
        }

        using(BinaryWriter binWriter =
            new BinaryWriter(new MemoryStream()))
        {
            // Write the data to the stream.
            Console.WriteLine("Writing data to the stream.");
            for(i = 0; i < arrayLength; i++)
            {
                binWriter.Write(dataArray[i]);
            }

            // Create a reader using the stream from the writer.
            using(BinaryReader binReader =
                new BinaryReader(binWriter.BaseStream))
            {
                try
                {
                    // Return to the beginning of the stream.
                    binReader.BaseStream.Position = 0;

                    // Read and verify the data.
                    Console.WriteLine("Verifying the written data.");
                    for(i = 0; i < arrayLength; i++)
                    {
                        if(binReader.ReadDouble() != dataArray[i])
                        {
                            Console.WriteLine("Error writing data.");
                            break;
                        }
                    }
                    Console.WriteLine("The data was written " +
                        "and verified.");
                }
                catch(EndOfStreamException e)
                {
                    Console.WriteLine("Error writing data: {0}.",
                        e.GetType().Name);
                }
            }
        }
    }
}
Imports System.IO

Public Class BinaryRW

    Shared Sub Main()
    
        Dim i As Integer
        Const upperBound As Integer = 1000

        ' Create random data to write to the stream.
        Dim dataArray(upperBound) As Double
        Dim randomGenerator As New Random()
        For i = 0 To upperBound
            dataArray(i) = 100.1 * randomGenerator.NextDouble()
        Next i

        Dim binWriter As New BinaryWriter(New MemoryStream())
        Try

            ' Write data to the stream.
            Console.WriteLine("Writing data to the stream.")
            
            For i = 0 To upperBound
                binWriter.Write(dataArray(i))
            Next i

            ' Create a reader using the stream from the writer.
            Dim binReader As New BinaryReader(binWriter.BaseStream)

            ' Return to the beginning of the stream.
            binReader.BaseStream.Position = 0

            ' Read and verify the data.
            Try
                Console.WriteLine("Verifying the written data.")
                For i = 0 To upperBound
                    If binReader.ReadDouble() <> dataArray(i) Then
                        Console.WriteLine("Error writing data.")
                        Exit For
                    End If
                Next i
                Console.WriteLine("The data was written and verified.")
            Catch ex As EndOfStreamException
                Console.WriteLine("Error writing data: {0}.", _
                    ex.GetType().Name)
            End Try
        Finally
            binWriter.Close()
        End Try

    End Sub
End Class

注釈

EndOfStreamException では、値が0x80070026されている HRESULT COR_E_ENDOFSTREAMが使用されます。

コンストラクター

名前 説明
EndOfStreamException()

メッセージ文字列をシステム指定メッセージに設定し、HRESULT を COR_E_ENDOFSTREAM に設定して、 EndOfStreamException クラスの新しいインスタンスを初期化します。

EndOfStreamException(SerializationInfo, StreamingContext)

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

EndOfStreamException(String, Exception)

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

EndOfStreamException(String)

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

プロパティ

名前 説明
Data

例外に関する追加のユーザー定義情報を提供するキーと値のペアのコレクションを取得します。

(継承元 Exception)
HelpLink

この例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。

(継承元 Exception)
HResult

特定の例外に割り当てられるコード化された数値である HRESULT を取得または設定します。

(継承元 Exception)
InnerException

現在の例外の原因となった Exception インスタンスを取得します。

(継承元 Exception)
Message

現在の例外を説明するメッセージを取得します。

(継承元 Exception)
Source

エラーの原因となるアプリケーションまたはオブジェクトの名前を取得または設定します。

(継承元 Exception)
StackTrace

呼び出し履歴のイミディエイト フレームの文字列表現を取得します。

(継承元 Exception)
TargetSite

現在の例外をスローするメソッドを取得します。

(継承元 Exception)

メソッド

名前 説明
Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetBaseException()

派生クラスでオーバーライドされた場合、1 つ以上の後続の例外の根本原因である Exception を返します。

(継承元 Exception)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetObjectData(SerializationInfo, StreamingContext)

派生クラスでオーバーライドされた場合は、例外に関する情報を使用して SerializationInfo を設定します。

(継承元 Exception)
GetType()

現在のインスタンスのランタイム型を取得します。

(継承元 Exception)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

現在の例外の文字列形式を作成して返します。

(継承元 Exception)

イベント

名前 説明
SerializeObjectState

例外に関するシリアル化されたデータを含む例外状態オブジェクトを作成するために例外がシリアル化されるときに発生します。

(継承元 Exception)

適用対象

こちらもご覧ください