Skip to content
_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN DE
Let's talk

Rust Error Handling

20. 08. 2022 Updated: 24. 03. 2026 1 min read intermediate
This article was published in 2022. Some information may be outdated.

Rust has no exceptions. Instead, Result and Option — explicit, type-safe error handling.

Result and Option

use std::fs; fn read_config(path: &str) -> Result { fs::read_to_string(path) } fn find_user(id: u32) -> Option { users.iter().find(|u| u.id == id).cloned() } // ? operator — error propagation fn process() -> Result<(), Box> { let config = fs::read_to_string(“config.toml”)?; let data: Config = toml::from_str(&config)?; Ok(()) }

Custom error types

use thiserror::Error;

[derive(Error, Debug)]

enum AppError {

[error(“User not found: {0}”)]

UserNotFound(u32),

[error(“Database error”)]

Database(#[from] sqlx::Error),

[error(“Invalid input: {0}”)]

Validation(String), }

Key Takeaway

Result for errors, Option for nullable. ? operator for propagation. thiserror for custom error types.

rusterror handlingprogramming
Share:

CORE SYSTEMS team

We build core systems and AI agents that keep operations running. 15 years of experience with enterprise IT.