If you were designing a standard library of a high level language (like Rust, C++, etc.) what would it do if while getting the current time of day (e.g. SystemTime::now()
) it encountered a failed kernel system call (e.g. to clock_gettime
) and why?
What do you think the existing implementations do?
- Return error or raise exception
- Return 0
- Return undefined values (like stack garbage)
- Panic/crash/segfault
For Rust, return Result<> , as is idomatic in Rust.
Another possible method is having an installable handler that handles the error at the place it is detected. Common Lisp does that and it is very powerful.
Rust seems to think panicking is better: https://github.com/rust-lang/rust/issues/115482