|
Dit artikel is gepubliceerd op zondag 31 juli 2011 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 2010 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() Catch ex As System. OutOfMemoryException Catch ex As System.IO. IOException End Try Catch ex As System. ArgumentNullException Catch ex As System. ArgumentException Catch ex As System.IO. FileNotFoundException Catch ex As System.IO. DirectoryNotFoundException Catch ex As System.IO. IOException 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 Catch ex As System. NotSupportedException Catch ex As System.IO. IOException End Try Catch ex As System. UnauthorizedAccessException Catch ex As System. ArgumentNullException Catch ex As System. ArgumentException Catch ex As System.IO. DirectoryNotFoundException Catch ex As System.IO. PathTooLongException Catch ex As System.IO. IOException Catch ex As System.Security. SecurityException Finally If streamWriter IsNot Nothing Then streamWriter.Close() End Try Console.ReadLine() End SubEnd ModuleDownload Visual Basic 2010 Broncode Download Visual C# Sourcecode
Dit artikel is gepubliceerd op zondag 31 juli 2011 op vbvoorbeelden, bezoek de website voor een recente versie van dit artikel of andere artikels.
|