homeboekenlinksledenabonneer je :Blijf op de hoogte door je te abonneren op de vbvoorbeelden RSS Niews Feed!Blijf op de hoogte door vbvoorbeelden te volgen op Twitter!Blijf op de hoogte door fan te worden van vbvoorbeelden op Facebook!
Visual Basic 2008 en 2010 Voorbeelden en Boeken Microsoft Visual Studio 2010Microsoft Developers Network - Visual BasicMicrosoft .NET Framework

visual basic 2008 voorbeelden en boeken / visual basic 2010 voorbeelden en boeken

10.3. System.IO Excepties - IOExceptions

Print Email Deel op FacebookDeel op TwitterDeel op DiggBookmark op Google BookmarksDeel op del.icio.usOverige Sociale Netwerksites...

Dit artikel is gepubliceerd op woensdag 28 april 2010 op vbvoorbeelden, bezoek de website voor een recente versie van dit artikel of andere artikels.

Net als zovele klassen en methods kunnen ook hier excepties optreden.

Voor de hand liggende excepties zijn deze waar je foutief zou verwijzen naar een bestand waarin wordt gelezen of geschreven, of excepties die optreden bij het benaderen van bestanden waar je niet voor ge-authoriseerd bent.
Visual Basic Broncode
Module IOExceptionsExample
    Sub Main()
        Dim path As String = "..."
        Dim streamReader As System.IO.StreamReader
        Try
            streamReader = New System.IO.StreamReader(path)
            Try
                streamReader.ReadToEnd() ' or : streamReader.ReadLine()
            Catch ex As System.OutOfMemoryException
                ' there is insufficient memory to allocate a buffer for
                ' the returned string
            Catch ex As System.IO.IOException
                ' an I/O error occurs
            End Try
        Catch ex As System.ArgumentNullException
            ' path is null
        Catch ex As System.ArgumentException
            ' path is an empty string
        Catch ex As System.IO.FileNotFoundException
            ' the file cannot be found
        Catch ex As System.IO.DirectoryNotFoundException
            ' the specified path is invalid, such as being on an unmapped drive
        Catch ex As System.IO.IOException
            ' path includes an incorrect or invalid syntax for file name,
            ' directory name, or volume label
        Finally
            If streamReader IsNot Nothing Then streamReader.Close()
        End Try
        '
        Dim streamWriter As System.IO.StreamWriter
        Try
            streamWriter = New System.IO.StreamWriter(path)
            Try
                streamWriter.Write("...")
            Catch ex As System.ObjectDisposedException
                ' AutoFlush is true or the buffer is full, and current writer
                ' is closed.
            Catch ex As System.NotSupportedException
                ' AutoFlush is true or buffer is full, and the contents of the
                ' buffer cannot be written to the underlying fixed size stream
                ' because the cursor is at the end the stream
            Catch ex As System.IO.IOException
                ' an I/O error occurs
            End Try
        Catch ex As System.UnauthorizedAccessException
            ' access is denied
        Catch ex As System.ArgumentNullException
            ' path is null
        Catch ex As System.ArgumentException
            ' path is an empty string ( "" ) or path contains the name of a
            ' system device (com1, com2, and so on)
        Catch ex As System.IO.DirectoryNotFoundException
            ' the specified path is invalid, such as being on an unmapped drive
        Catch ex As System.IO.PathTooLongException
            ' the specified path, file name, or both exceed the system-defined
            ' maximum length
        Catch ex As System.IO.IOException
            ' path includes an incorrect or invalid syntax for file name,
            ' directory name, or volume label syntax
        Catch ex As System.Security.SecurityException
            ' the caller does not have the required permission
        Finally
            If streamWriter IsNot Nothing Then streamWriter.Close()
        End Try
        '
        Console.ReadLine()
    End Sub
End Module

Dit artikel is gepubliceerd op woensdag 28 april 2010 op vbvoorbeelden, bezoek de website voor een recente versie van dit artikel of andere artikels.

Visual Basic 2008 & 2010 Boeken

Het Groene Visual Basic 2008 & 2010 Voorbeelden Boek Het Blauwe Visual Basic 2008 & 2010 Voorbeelden Boek Het Rode Visual Basic 2008 & 2010 Voorbeelden Boek

Bevalt een artikel je, dan kan je de inhoud van vbvoorbeelden ook reclamevrij in boekvorm verkrijgen.

De inhoud is verdeeld over 3 boeken, Het Groene, Het Blauwe en Het Rode Visual Basic 2008 & 2010 Voorbeelden Boek.

Klik hier voor meer informatie.

Berichten

Fast UML Sequence Diagram Editor