Class FileException
Exception thrown when a file I/O operation performed by ScyllaFileUtil or its
supporting subsystems fails for any reason.
Implements
Inherited Members
Namespace: Scylla.Core.Util.File
Assembly: ScyllaCore.dll
Syntax
public class FileException : Exception, ISerializable
Remarks
FileException always carries a FileErrorCode that categorizes
the failure so callers can implement targeted error handling without parsing message strings.
When a standard .NET exception is the root cause, the internal wrapping logic in
FileIOUtil.WrapException maps it to the most appropriate FileErrorCode
and preserves the original exception as InnerException.
The optional FilePath property carries the file system path associated with the failure when it is known, which aids debugging log messages and error dialogs.
try
{
var text = ScyllaFileUtil.ReadText("data/config.json");
}
catch (FileException ex)
{
switch (ex.ErrorCode)
{
case FileErrorCode.FileNotFound:
/* Create a default config. */
break;
case FileErrorCode.AccessDenied:
Log.Error($"Cannot read '{ex.FilePath}': access denied.", LogCategory.Core);
break;
default:
throw;
}
}
Constructors
FileException(FileErrorCode)
Initializes a new instance of the FileException class with a
specified error code. The exception message is derived automatically from
errorCode via the internal default-message table.
Declaration
public FileException(FileErrorCode errorCode)
Parameters
| Type | Name | Description |
|---|---|---|
| FileErrorCode | errorCode | A FileErrorCode value that categorizes the failure. The generated message text matches the English description for that code. |
FileException(FileErrorCode, string)
Initializes a new instance of the FileException class with a specified error code and a custom human-readable message. Use this overload when the default message text is too generic and additional context is available (for example, including the invalid character or the rejected path).
Declaration
public FileException(FileErrorCode errorCode, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| FileErrorCode | errorCode | A FileErrorCode value that categorizes the failure. |
| string | message | A developer- or user-facing description of the error. Should not be |
FileException(FileErrorCode, string, Exception)
Initializes a new instance of the FileException class with a specified error code, message, and the original .NET exception that caused the failure. Use this overload when wrapping a caught system exception so that the full exception chain is preserved in InnerException.
Declaration
public FileException(FileErrorCode errorCode, string message, Exception innerException)
Parameters
| Type | Name | Description |
|---|---|---|
| FileErrorCode | errorCode | A FileErrorCode value that categorizes the failure. |
| string | message | A human-readable description of the error. |
| Exception | innerException | The exception that is the root cause of the current failure, or |
FileException(FileErrorCode, string, string)
Initializes a new instance of the FileException class with a specified error code, message, and the file path that triggered the failure. Prefer this overload whenever the file system path is known so that callers can log or display it without having to parse the message string.
Declaration
public FileException(FileErrorCode errorCode, string message, string filePath)
Parameters
| Type | Name | Description |
|---|---|---|
| FileErrorCode | errorCode | A FileErrorCode value that categorizes the failure. |
| string | message | A human-readable description of the error. |
| string | filePath | The absolute or relative file system path involved in the failed operation.
May be |
FileException(FileErrorCode, string, string, Exception)
Initializes a new instance of the FileException class with a
specified error code, message, file path, and inner exception. This is the most
complete overload and is typically used by FileIOUtil.WrapException when
converting a caught .NET exception into a structured FileException.
Declaration
public FileException(FileErrorCode errorCode, string message, string filePath, Exception innerException)
Parameters
| Type | Name | Description |
|---|---|---|
| FileErrorCode | errorCode | A FileErrorCode value that categorizes the failure. |
| string | message | A human-readable description of the error. |
| string | filePath | The absolute or relative file system path involved in the failed operation,
or |
| Exception | innerException | The exception that is the root cause of the current failure, or |
Properties
ErrorCode
Gets the structured error code that categorizes the type of file I/O failure.
Use this value in switch or if statements to implement targeted
recovery logic without relying on exception message strings.
Declaration
public FileErrorCode ErrorCode { get; }
Property Value
| Type | Description |
|---|---|
| FileErrorCode | A FileErrorCode value that is never |
FilePath
Gets the file system path associated with the failed operation, or null
if the path was not available or relevant at the time the exception was raised.
Declaration
public string FilePath { get; }
Property Value
| Type | Description |
|---|---|
| string | An absolute or relative path string as provided to the originating API call,
or |