IOException
Class
The exception that is thrown when an I/O error occurs.
Inheritance
object
Exception
IOException
Remarks
The IOException
class is the base class for exceptions thrown by the System.IO
namespace. It is thrown when an error occurs during an I/O operation, such as reading from or writing to a file.
Common scenarios that can lead to an IOException
include:
- A file not being found.
- Insufficient permissions to access a file.
- A disk being full.
- A network error during a network stream operation.
You can catch IOException
to handle I/O errors gracefully in your application. For more specific error handling, you can catch derived exception types such as FileNotFoundException
, DirectoryNotFoundException
, or UnauthorizedAccessException
.
Constructors
Name | Description |
---|---|
IOException() |
Initializes a new instance of the IOException class. |
IOException(string message) |
Initializes a new instance of the IOException class with a specified error message and a reference to the inner exception that is the cause of this exception. |
IOException(string message, Exception innerException) |
Initializes a new instance of the IOException class with a specified error message. |
IOException(string message, int hresult) |
Initializes a new instance of the IOException class with a specified error message and HRESULT. |
Properties
Name | Description |
---|---|
Message |
Gets an informative message that describes the current exception. |
HResult |
Gets or sets the HRESULT value that is assigned to the generated exception and that identifies the specific exception. |
Source |
Gets or sets the name of the application or the object that causes the error. |
Methods
Name | Description |
---|---|
GetBaseException() |
When overridden in a derived class, returns the Exception that is the root cause of the current exception. |
Constructor
IOException()
Initializes a new instance of the IOException
class.
public IOException();
Constructor
IOException(string message)
Initializes a new instance of the IOException
class with a specified error message.
public IOException(string message);
Constructor
IOException(string message, Exception innerException)
Initializes a new instance of the IOException
class with a specified error message and a reference to the inner exception that is the cause of this exception.
public IOException(string message, Exception innerException);
Constructor
IOException(string message, int hresult)
Initializes a new instance of the IOException
class with a specified error message and HRESULT.
public IOException(string message, int hresult);
Property
Message
Gets an informative message that describes the current exception.
public override string Message { get; }
Property
HResult
Gets or sets the HRESULT value that is assigned to the generated exception and that identifies the specific exception.
public int HResult { get; set; }
Property
Source
Gets or sets the name of the application or the object that causes the error.
public string Source { get; set; }
Method
GetBaseException()
When overridden in a derived class, returns the Exception
that is the root cause of the current exception.
public Exception GetBaseException();