Share via


IOException 类

发生 I/O 错误时引发的异常。

**命名空间:**System.IO
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class IOException
    Inherits SystemException
用法
Dim instance As IOException
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class IOException : SystemException
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class IOException : public SystemException
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class IOException extends SystemException
SerializableAttribute 
ComVisibleAttribute(true) 
public class IOException extends SystemException

备注

IOException 是使用流、文件和目录访问信息时引发的异常的基类。

“基类库”包括下列类型,每种类型都是 IOException 的一个派生类:

在合适的场合,请使用这些类型而不是 IOException。

IOException 使用包含值 0x80131620 的 HRESULT COR_E_IO。

示例

此代码示例是为 FileStream.Lock 方法提供的一个更大示例的一部分。

' Catch the IOException generated if the 
' specified part of the file is locked.
Catch ex As IOException
    Console.WriteLine( _
        "{0}: The write operation could " & _
        "not be performed because the " & _
        "specified part of the file is " & _
        "locked.", ex.GetType().Name)
End Try
// Catch the IOException generated if the 
// specified part of the file is locked.
catch(IOException e)
{
    Console.WriteLine(
        "{0}: The write operation could not " +
        "be performed because the specified " +
        "part of the file is locked.", 
        e.GetType().Name);
}
// Catch the IOException generated if the 
// specified part of the file is locked.
catch ( IOException^ e ) 
{
   Console::WriteLine( "{0}: The write operation could not "
   "be performed because the specified "
   "part of the file is locked.", e->GetType()->Name );
}

// Catch the IOException generated if the 
// specified part of the file is locked.
catch(IOException e) {                        
    Console.WriteLine(
        "{0}: The write operation could not "
        + "be performed because the specified "
        + "part of the file is locked.", 
        e.GetType().get_Name());
}

继承层次结构

System.Object
   System.Exception
     System.SystemException
      System.IO.IOException
         派生类

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

IOException 成员
System.IO 命名空间
Exception

其他资源

处理和引发异常
文件和流 I/O
如何:从文件读取文本
如何:向文件写入文本