# No exceptions

> Why nothing in the framework throws to report a failure, what it does instead — empty resources, defaults, results, warnings said once — and what that leaves to your game.

Source: https://omardev29.github.io/rmp-docs/framework/why/no-exceptions.html

No function of the framework throws to tell you something went wrong. A texture that fails to load is an empty texture; a key missing from a save reads as the default you gave it; a mistake in how the game uses the framework is a warning, said once. You never need a `try` around a call to `rmp::`.

## Why

Three reasons, and each would be enough on its own.

- **Many game builds switch exceptions off.** A library that reports failure by throwing cannot be used by a game compiled without them.
- **raylib is C.** An exception thrown inside a callback that raylib's C code is running — and on the web and on iOS the whole frame is such a callback — would have to unwind through C frames, which C++ does not define.
- **A frame is a sequence that has to finish.** Throwing out of the middle of one leaves `BeginDrawing()` without its `EndDrawing()`, a UI frame open and a scene change half applied. Something has to put all of that right, and a framework that never throws never has to.

## What it does instead

Every failure is turned into a value at the place it happens, and the value is chosen so that the obvious code is also the correct code.

### An asset that fails to load is empty

It has no texture in it, `valid()` is false, and drawing it draws nothing — the same as raylib does with a zeroed struct. A missing picture is a hole in the frame, not a dead process. The failure is still counted: the boot line CI reads reports how many assets failed to load, and a boot with any failure is red.

A file that is there and does not decode — a picture, a sound, a song or a font cut short or corrupt — is a failed load in the same way: what comes back is empty, the failure is counted, and the log says so once per name. A font is no exception. raylib answers a font it cannot read with its own built-in one, and the framework does not take that for the file you asked for: you get an empty font, and nothing is kept under the file's name, so the same name is tried again the next time it is asked for.

```cpp
rmp::Texture _logo;

void _ready() override {
    _logo = rmp::assets::load_texture("logo.png");
    if (!_logo) TraceLog(LOG_WARNING, "no logo; the title is drawn as text");
}
```

### A read has a default

Reading a save never throws and never crashes on what it finds. `read()` returns a [`Result`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#Result) that is true in an `if` only when the save was read and checked, and whose [`status`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#Status) says why when it was not: missing, cut short, edited, or not a save at all. And every value read out of an [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html) takes the default to use when the key is not there or holds the wrong type, which is what lets an update to a game read the saves of the version before it.

```cpp
rmp::Value save;
const rmp::save::Result got = rmp::save::read("slot1", save);
if (got.status == rmp::save::Status::MODIFIED) {
    TraceLog(LOG_WARNING, "the save was edited or damaged; starting over");
}
const int level = save["level"].as_int(1);
const float volume = save["settings"]["volume"].as_float(0.8f);
```

### A lookup can come back empty

Where the caller may want to know, the answer is an empty [`rmp::Ref`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Ref.html) or a `false`: [`get<B>()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#get) comes back empty when the object has no such behavior, a [`Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html) is empty once its object is gone, and [`rmp::save::write()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#write) returns whether the save reached the disk.

And forgetting to ask does not crash either. Reaching through an empty one with `->` or `*` is a mistake in the game, said once in the log for each type, and the line goes to a stand-in: a `B` made for the purpose, so a read gives the default and a write lands nowhere. A type with no default constructor has no stand-in, and for that one the program ends there, after the same message.

### A mistake in the game is said once

Asking for an input action nobody defined, playing an animation tag that is not in the sheet, popping the last scene: these are mistakes in the game, and the framework says so in the log — once per place in the code, not sixty times a second — and carries on doing the harmless thing. The macro behind it, RMP_REPORT_ONCE in `src/rmp/internal.h`, is described in [Macros](https://omardev29.github.io/rmp-docs/framework/why/macros.html#report-once).

A warning in a log is easy to miss, so a debug build can make it impossible to miss. [`[dev] strict = true`](https://omardev29.github.io/rmp-docs/reference/configuration.html#dev-strict) turns the first one into an abort with the message, in debug builds only:

raylib_multiplatform.toml

```toml
[dev]
strict = true
```

### A condition of the machine is not a mistake

No sound device, a disk that refused a write, a portable build in a folder it cannot write to: none of those is a mistake in the game, and strict mode never aborts on them. The framework logs them once, plainly, and the calls that depend on them do nothing, or return `false`, instead of failing — a game on a machine with no sound card runs, silently, under strict mode too.

### Leaving is a flag

[`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit) is the case where an exception is most tempting — unwind everything and leave — and it is a flag instead. The frame that asked finishes, and the game shuts down in order.

## Exceptions from underneath

The C++ standard library does throw, in a few places the framework relies on — asking the operating system for random bytes, converting a Windows path to UTF-8 — and those are caught where they happen, in three places in `src/rmp/save/save.cpp`, and turned into a value: another source for the random bytes, an empty path that the caller already treats as "cannot be used". None of them escapes into your game.

It is also why the framework vendors only the math headers of raylib-cpp: its resource classes throw on a failed load, and the math ones have no failure to report.

## What it leaves to your game

The framework is not compiled with exceptions switched off, and nothing stops your own code using them. What it promises is the other direction: nothing it calls will throw at you to report a failure. The UI goes one step further. A container's contents are a lambda of yours, and if that lambda throws, the container is still closed on the way out, so the next frame's layout is not corrupted.
