codice:
try {
    $file = @fopen("cani.txt", "r");
    if (!$file)
        throw new Exception("Impossibile aprire file.");
    
    while ($row = fread($file)) {
        if (condizioneErrore)
            throw new Exception("Messaggio di errore");
    }
}
catch(Exception $e) {
    print("E' avvenuto un errore: " . $e->getMessage();
    exit();
}