---
title: "Errors and Translations"
description: "The exceptions of Derafu File and how to translate their messages"
type: "docs"
category: "doc"
tags: []
authors: [Anonymous]
date: "2026-11-05"
last_update: "2026-11-05"
time_minutes: 2
draft: false
unlisted: false
url: "https://www.derafu.dev/docs/core/file/errors"
---

# Errors and Translations

Every failure of the file system is a `Derafu\File\Exception\FileException`, which extends `TranslatableRuntimeException` of [`derafu/translation`](https://www.derafu.dev/docs/core/translation). Catching `FileException`, or PHP's `RuntimeException`, catches all of them.

| Exception | When |
| --- | --- |
| `FileException` | A creation, a reading, a writing, a move, a deletion or an archive fails. |
| `FileNotFoundException` | A file, a directory or a path that must exist does not. |
| `FileAccessException` | It exists, but it is not of the expected kind (a directory instead of a file) or it can not be read or written. |
| `PathException` | A path has a null character, or it leaves the directory that it must stay in. |

The last three extend `FileException`. The messages name the file, the directory or the path:

```php
try {
    File::read('/var/app/missing.txt');
} catch (FileNotFoundException $e) {
    $e->getMessage();   // The file does not exist: /var/app/missing.txt
}
```

A wrong argument is not a file error. `TempFile::with()` and `Zip::fromContents()` throw a `TranslatableInvalidArgumentException` (an invalid extension, prefix or entry name, or a content that is not a string).

## Translations

The messages are translatable and the Spanish translations ship with the package. To have them in your translator, import its services (or add `FileTranslationResourceProvider` to the resource providers of the translator):

```yaml
imports:
    - { resource: '../vendor/derafu/file/resources/config/file-services.yaml' }
```

With the translator, the message of the example above is `El archivo no existe: /var/app/missing.txt`.



---
Last updated on 05/11/2026

