EndOfStreamException Classe

Definizione

Eccezione generata durante il tentativo di lettura oltre la fine di un flusso.

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
Ereditarietà
EndOfStreamException
Ereditarietà
Attributi

Esempio

Nell'esempio di codice seguente viene illustrato come leggere e scrivere Double dati in memoria usando le BinaryReader classi e BinaryWriter nella MemoryStream classe .

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

Commenti

EndOfStreamException usa il COR_E_ENDOFSTREAM HRESULT, che ha il valore 0x80070026.

Costruttori

Nome Descrizione
EndOfStreamException()

Inizializza una nuova istanza della classe con la EndOfStreamException relativa stringa di messaggio impostata su un messaggio fornito dal sistema e il relativo HRESULT impostato su COR_E_ENDOFSTREAM.

EndOfStreamException(SerializationInfo, StreamingContext)

Inizializza una nuova istanza della EndOfStreamException classe con le informazioni di serializzazione e contesto specificate.

EndOfStreamException(String, Exception)

Inizializza una nuova istanza della classe EndOfStreamException con un messaggio di errore specificato e un riferimento all'eccezione interna che è la causa di questa eccezione.

EndOfStreamException(String)

Inizializza una nuova istanza della classe con la EndOfStreamException relativa stringa di messaggio impostata su message e il relativo HRESULT impostato su COR_E_ENDOFSTREAM.

Proprietà

Nome Descrizione
Data

Ottiene una raccolta di coppie chiave/valore che forniscono informazioni aggiuntive definite dall'utente sull'eccezione.

(Ereditato da Exception)
HelpLink

Ottiene o imposta un collegamento al file della Guida associato a questa eccezione.

(Ereditato da Exception)
HResult

Ottiene o imposta HRESULT, valore numerico codificato assegnato a un'eccezione specifica.

(Ereditato da Exception)
InnerException

Ottiene l'istanza Exception che ha causato l'eccezione corrente.

(Ereditato da Exception)
Message

Ottiene un messaggio che descrive l'eccezione corrente.

(Ereditato da Exception)
Source

Ottiene o imposta il nome dell'applicazione o dell'oggetto che causa l'errore.

(Ereditato da Exception)
StackTrace

Ottiene una rappresentazione di stringa dei fotogrammi immediati nello stack di chiamate.

(Ereditato da Exception)
TargetSite

Ottiene il metodo che genera l'eccezione corrente.

(Ereditato da Exception)

Metodi

Nome Descrizione
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetBaseException()

Quando sottoposto a override in una classe derivata, restituisce l'oggetto Exception che rappresenta la causa radice di una o più eccezioni successive.

(Ereditato da Exception)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetObjectData(SerializationInfo, StreamingContext)

In caso di override in una classe derivata, imposta con le SerializationInfo informazioni sull'eccezione.

(Ereditato da Exception)
GetType()

Ottiene il tipo di runtime dell'istanza corrente.

(Ereditato da Exception)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Crea e restituisce una rappresentazione di stringa dell'eccezione corrente.

(Ereditato da Exception)

Eventi

Nome Descrizione
SerializeObjectState

Si verifica quando viene serializzata un'eccezione per creare un oggetto stato dell'eccezione contenente dati serializzati sull'eccezione.

(Ereditato da Exception)

Si applica a

Vedi anche