this post was submitted on 21 Nov 2025
250 points (96.6% liked)

Technology

76992 readers
3064 users here now

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related news or articles.
  3. Be excellent to each other!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, this includes using AI responses and summaries. To ask if your bot can be added please contact a mod.
  9. Check for duplicates before posting, duplicates may be removed
  10. Accounts 7 days and younger will have their posts automatically removed.

Approved Bots


founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] calcopiritus@lemmy.world 6 points 1 day ago (5 children)

Replace uncaught exception for unhanded error.

[–] sugar_in_your_tea@sh.itjust.works 1 points 17 hours ago* (last edited 17 hours ago) (3 children)

No, it's a panic, so it's more similar to a segfault, but with some amount of unwinding. It can be "caught" but only at a thread boundary.

[–] calcopiritus@lemmy.world 1 points 7 hours ago* (last edited 7 hours ago) (2 children)

An unhanded error will always result on a panic (or a halt I guess). You cannot continue the execution of the program without handling an error (remember, just ignoring it is a form of handling). You either handle the error and continue execution, or you don't and stop execution.

A panic is very far from a segfault. In apparent result, it is the same. However, a panic is a controlled stopping of the program's execution. A segfault is a forced execution stop by the OS.

But the OS can only know that it has to segfault if a program accesses memory outside its control.

If the program accesses memory that it's under it's control, but is outside bounds, then the program will not stop the execution, and this is way worse.

EDIT: As you said, it's also an important difference that a panic will just stop the thread, not the entire process.

[–] sugar_in_your_tea@sh.itjust.works 1 points 3 hours ago (1 children)

Yes, it's not the same since you get a stacktrace (if enabled) and a message, but it's the closest thing you get in safe rust (outside compiler bugs). I compare it to a segfault because it's almost as unhandleble.

Basically, you don't want a panic to crash your program in most cases. If you do, make it explicit (i.e. with expect()). unwrap() tells me the value is absolutely there or the dev is lazy, and I always assume the latter unless there's an explanation (or it's obvious from context) otherwise.

[–] calcopiritus@lemmy.world 1 points 2 hours ago

I see you ignored my entire comment.

I don't know what is more explicit about expect. Unwrap is as explicit as it gets without directly calling panic!, it's only 1 abstraction level away. It's literally the same as expect, but without a string argument. It's probably top 10 functions most commonly used in rust, every rust programmer knows what unwrap does.

Any code reviewer should be able to see that unwrap and flag it as a potential issue. It's not a weird function with an obscure panic side effect. It can only do 2 things: panic or not panic, it can be implemented in a single line. 3 lines if the panic! Is on a different line to the if statement.

load more comments (1 replies)