Skip to content

CkFileException

What CkFile throws — only when asked.

Raised by any CkFile method called with throwIfInvalid: true when a value could not be used. Never thrown otherwise: by default every CkFile method returns empty or false instead. Final, and derived from CkException.

The message names the method, shows the value with its type, says what it was meant to be and why it failed:

CkFile.RelativePath: cannot use "../secrets.txt" (String) as a relative path — it climbs out of its folder (..).

Properties

Every property is public readonly.

Property Type What it holds
Expected string What the value was meant to be — 'a file name', 'a relative path'.
Input mixed From CkException: the value that failed, untouched.
Reason string From CkException: why, in a few words.

Quick look

use SafeCoder\CommonKit\CkFile;
use SafeCoder\CommonKit\Exceptions\CkFileException;

try {
    CkFile::RelativePath(
        input: '../secrets.txt',
        throwIfInvalid: true
    );
} catch (CkFileException $error) {
    echo $error->Reason;     // -> 'it climbs out of its folder (..)'
    echo $error->Expected;   // -> 'a relative path'
}