Skip to content

CkMediaException

What CkMedia throws — only when asked.

Raised by CkMedia::YouTube, CkMedia::Vimeo, CkMedia::Video, CkMedia::Image or CkMedia::Audio called with throwIfInvalid: true when the value names no video or file. Never thrown otherwise: by default the method hands back an object whose IsValid() is 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:

CkMedia.YouTube: cannot use "https://example.com/" (String) as a YouTube address — not a YouTube address.

Properties

Every property is public readonly.

Property Type What it holds
Expected string What the value was meant to be — 'a YouTube address', 'a Vimeo address', 'a video address', 'an image address', 'an audio address'.
Input mixed From CkException: the value that failed, untouched.
Reason string From CkException: why, in a few words — 'not a YouTube address', 'no video code in the address', 'not a video address', 'not a video file', 'not an image address', 'not an image file', 'not an audio address', 'not an audio file', 'no value'.

Quick look

use SafeCoder\CommonKit\CkMedia;
use SafeCoder\CommonKit\Exceptions\CkMediaException;

try {
    CkMedia::YouTube(
        input: 'https://example.com/',
        throwIfInvalid: true
    );
} catch (CkMediaException $error) {
    echo $error->Reason;     // -> 'not a YouTube address'
    echo $error->Expected;   // -> 'a YouTube address'
}

try {
    CkMedia::Video(
        input: 'https://cdn.example.com/clip.mkv',
        throwIfInvalid: true
    );
} catch (CkMediaException $error) {
    echo $error->Reason;     // -> 'not a video file'
    echo $error->Expected;   // -> 'a video address'
}