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
- 繼承
- 繼承
- 屬性
範例
以下程式碼範例展示了如何在類別上Double方使用 BinaryReader and BinaryWriter 類別來讀寫MemoryStream資料到記憶體。
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 使用 HRESULT COR_E_ENDOFSTREAM,其值為 0x80070026。
建構函式
| 名稱 | Description |
|---|---|
| EndOfStreamException() |
初始化一個新的類別實例 EndOfStreamException ,其訊息字串設為系統提供的訊息,HRESULT 設為 COR_E_ENDOFSTREAM。 |
| EndOfStreamException(SerializationInfo, StreamingContext) |
已淘汰.
使用指定的串行化和內容資訊,初始化 EndOfStreamException 類別的新實例。 |
| EndOfStreamException(String, Exception) |
初始化類別的新實例 EndOfStreamException ,並附上指定的錯誤訊息及導致該異常的內部例外的參考。 |
| EndOfStreamException(String) |
初始化一個新的類別實例 EndOfStreamException ,將訊息字串設為 , |
屬性
| 名稱 | Description |
|---|---|
| Data |
取得一組鍵值對,提供關於例外的額外使用者定義資訊。 (繼承來源 Exception) |
| HelpLink |
取得或設定與此例外相關的說明檔案連結。 (繼承來源 Exception) |
| HResult |
取得或設定 HRESULT,一個編碼的數值,指派給特定例外。 (繼承來源 Exception) |
| InnerException |
會取得 Exception 造成目前例外的實例。 (繼承來源 Exception) |
| Message |
取得描述目前例外狀況的訊息。 (繼承來源 Exception) |
| Source |
取得或設定造成錯誤之應用程式或物件的名稱。 (繼承來源 Exception) |
| StackTrace |
會取得呼叫堆疊上即時框架的字串表示。 (繼承來源 Exception) |
| TargetSite |
會取得拋出當前例外的方法。 (繼承來源 Exception) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetBaseException() |
當在派生類別中被覆寫時,回傳 Exception 是一個或多個後續例外的根因。 (繼承來源 Exception) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
已淘汰.
在衍生類別中覆寫時,使用例外狀況的相關信息來設定 SerializationInfo。 (繼承來源 Exception) |
| GetType() |
取得目前實例的執行時型態。 (繼承來源 Exception) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
建立並回傳當前例外的字串表示。 (繼承來源 Exception) |
事件
| 名稱 | Description |
|---|---|
| SerializeObjectState |
已淘汰.
當例外被序列化以建立包含該例外序列化資料的例外狀態物件時,會發生這種情況。 (繼承來源 Exception) |