EndOfStreamException クラス
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ストリームの末尾を越えて読み取ろうとしたときにスローされる例外。
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
- 継承
- 継承
- 属性
次のコード例は、 クラスの上部にある クラスと クラスを使用BinaryReaderして、メモリへのデータの読み取りとBinaryWriter書き込みを行うDouble
方法をMemoryStream示しています。
using namespace System;
using namespace System::IO;
int main()
{
int i;
const int arrayLength = 1000;
// Create random data to write to the stream.
array<double>^dataArray = gcnew array<double>(arrayLength);
Random^ randomGenerator = gcnew Random;
for ( i = 0; i < arrayLength; i++ )
{
dataArray[ i ] = 100.1 * randomGenerator->NextDouble();
}
BinaryWriter^ binWriter = gcnew BinaryWriter( gcnew MemoryStream );
try
{
// Write data to the stream.
Console::WriteLine( "Writing data to the stream." );
i = 0;
for ( i = 0; i < arrayLength; i++ )
{
binWriter->Write( dataArray[ i ] );
}
// Create a reader using the stream from the writer.
BinaryReader^ binReader = gcnew BinaryReader( binWriter->BaseStream );
// Return to the beginning of the stream.
binReader->BaseStream->Position = 0;
try
{
// Read and verify the data.
i = 0;
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 );
}
}
finally
{
binWriter->Close();
}
}
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を使用します。
End |
メッセージ文字列がシステムによって提供されたメッセージに設定され、HRESULT が COR_E_ENDOFSTREAM に設定された EndOfStreamException クラスの新しいインスタンスを初期化します。 |
End |
古い.
指定したシリアル化とコンテキスト情報を使用して、EndOfStreamException クラスの新しいインスタンスを初期化します。 |
End |
メッセージ文字列を |
End |
指定したエラー メッセージおよびこの例外の原因となった内部例外への参照を使用して、EndOfStreamException クラスの新しいインスタンスを初期化します。 |
Data |
例外に関する追加のユーザー定義情報を提供する、キーと値のペアのコレクションを取得します。 (継承元 Exception) |
Help |
この例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。 (継承元 Exception) |
HResult |
特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。 (継承元 Exception) |
Inner |
現在の例外の原因となる Exception インスタンスを取得します。 (継承元 Exception) |
Message |
現在の例外を説明するメッセージを取得します。 (継承元 Exception) |
Source |
エラーの原因となるアプリケーションまたはオブジェクトの名前を取得または設定します。 (継承元 Exception) |
Stack |
呼び出し履歴で直前のフレームの文字列形式を取得します。 (継承元 Exception) |
Target |
現在の例外がスローされたメソッドを取得します。 (継承元 Exception) |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
Get |
派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の根本原因である Exception を返します。 (継承元 Exception) |
Get |
既定のハッシュ関数として機能します。 (継承元 Object) |
Get |
古い.
派生クラスでオーバーライドされた場合は、その例外に関する情報を使用して SerializationInfo を設定します。 (継承元 Exception) |
Get |
現在のインスタンスのランタイム型を取得します。 (継承元 Exception) |
Memberwise |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
To |
現在の例外の文字列形式を作成して返します。 (継承元 Exception) |
Serialize |
古い.
例外がシリアル化され、例外に関するシリアル化されたデータを含む例外状態オブジェクトが作成されたときに発生します。 (継承元 Exception) |
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。