惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
博客园 - 【当耐特】
GbyAI
GbyAI
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
腾讯CDC
F
Fortinet All Blogs
IT之家
IT之家
WordPress大学
WordPress大学
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
DataBreaches.Net
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Help Net Security
V
Visual Studio Blog
小众软件
小众软件
Y
Y Combinator Blog

The Rust Programming Language Forum - Latest topics

Beginner building a Rust backend framework (AI-assisted) — feedback appreciated Re-exporting a trait with a custom derive_macro Gold linker is deprecated Why is using PhantomData valid in this case? Code review for Static Pool Allocator Looking for a pool based allocator Why is this legal? What does it mean for Rustc to run "out of TLS keys"? Using async/await internally with no internal runtime, but exposing a nonblocking poll API — is this a reasonable design? Testing functions that use randomness `cargo-path`: improve coding agents&#39; ability to find Rust documentation Rust task runners Lifetime weird case Windows - USB device not detected A random rustc-ice-[...].txt file appeared Develop rust where the environment is setup in a docker Undefined Behavior: in-bounds pointer arithmetic failed: attempting to offset pointer by 20 bytes, but got alloc238 which is only 1 byte from the end of the allocation Unbug 0.5 - Runtime debug assertions Is there a tiny error in section 6.2 Reference types? Lifetime woes implementing ratatui::Widget for a reference Rusqlite + Chrono: How do I simplify code to obtain chrono datetime value From OOP to Rust – struggling with code organization and data structure design Way to avoid a self-referential struct Rust RF and audio resources/communities Whyhttp - HTTP mocks that fail where the bug actually is Using tokio channel permits in a tower service Arc::increment_strong_count design question (cross-post) `&T`, `&mut T`, `Pin<&mut T>` and `&Cell<T>`: Ways of Borrowing a `T` Ratatui detect arrow key press and release Feedback about post in medium
C++ to Rust -- Exceptions
@AndrewOfC A · 2026-04-24 · via The Rust Programming Language Forum - Latest topics
C++ Exceptions One underappreciated feature of C++ is the ability to throw/catch exceptions. If one leverages the flexability of using different classes to represent different use-cases of 'exceptional behavior' a robust, readble, and extensible error handling system can be created and maintained. A best practice is to create classes of exception that will capture as much infomation about the cause of the exception before the actual 'throw' and to use that to provide the user or higher level developer with a more meaningful error message. try { MyObj.myOperation() } catch ( const FileNotFound& e ) { } catch ( const IllegalConfigurationException& e ) { } catch ( const SyntaxException& e ) { } catch (const std::exception& e) { } catch (...) { } Rust Rust, on the other hand, eschews exceptions. However, there is a feature in Rust that can be leveraged to create a similar pattern for error handling and provide much of the same of the same benefits using enums and the sugary '?' operator. Enums enum ErrorCases { FileNotFound(String), // provide expected path of the missing file IllegalConfiguration, SyntaxError(u32/*line*/, u32/*column*/, String/*file*/), Other(String), } fn my_file_operation(throw: bool) -> Result<(), ErrorCases> { if throw { Err(ErrorCases::FileNotFound("my_file.txt".to_string())) } else { Ok(()) } } fn my_syntax_error(throw: bool) -> Result<(), ErrorCases> { if throw { Err(ErrorCases::SyntaxError(10, 20, "my_file.txt".to_string())) } else { Ok(()) } } fn my_config_operation(throw: bool) -> Result<(), ErrorCases> { if throw { Err(ErrorCases::IllegalConfiguration) } else { Ok(()) } } fn my_other_operation(throw: bool) -> Result<(), ErrorCases> { if throw { Err(ErrorCases::Other("Unexpected error".to_string())) } else { Ok(()) } } fn my_operation() -> Result<(), ErrorCases> { my_file_operation(false)?; my_syntax_error(true)?; my_config_operation(false)?; my_other_operation(false)?; Ok(()) } fn main() { match my_operation() { Ok(_) => println!("Success"), Err(ErrorCases::FileNotFound(path)) => println!("File not found: {path}"), Err(ErrorCases::IllegalConfiguration) => println!("Illegal configuration"), Err(ErrorCases::SyntaxError(line, column, file)) => println!("Syntax error on line {line} column {column} in file {file}"), Err(ErrorCases::Other(msg)) => println!("Other error: {msg}"), } ; } This can also ensure thorough error handling. Introducing a new error case will trigger the compiler to warn that the error needs to be handled. Provided of course that we do not use the 'wildcard' pattern to catch unknowns.