12 ms·
That someone just need to say "Rust has exceptions which can't be handled". Ridiculous enough, but it's true. They made bigger confusion, in my opinion. When ev
by EugeneOZ 11y ago
That someone just need to say "Rust has exceptions which can't be handled". Ridiculous enough, but it's true. They made bigger confusion, in my opinion. When even standard lib's code use panic as way to report about error, we can't say "nobody use panics as exceptions".
- kbenson 11y agoExceptions that can't be caught are conceptually different, and different in practice, than exceptions that can be caught. To avoid confusion, it helps to call different things different names. I'm not sure why you are so adamant that two things that are similar one one aspect, but absolutely different in another aspect, need to be called the same thing.
- EugeneOZ 11y agoNot only me :) I admit it's arguable question and I think people with different opinions about this question will never understand each other. So let's agree to disagree. Rust FTW :)
- Gankro 11y agoWe use panics for logic errors. This is an important distinction. We will never throw if a file couldn't open, or if a string couldn't parse, because these are expected errors that you should explicitly handle. Catching panics should never be part of an application's normal control flow in Rust, unlike e.g. Java and C#. These languages use exceptions to indicate any error condition, and therefore writing correct error handling code requires try/catch. Exceptions in Rust are used as a "soft abort". A real abort tears down the entire process, and the OS handles releasing all associated resources. But if you're writing a program that has logical tasks that resemble processes, the OS can't individually tear those down for you. When an exception (panic) is thrown in Rust, the task has hit a situation that cannot be recovered, and tears itself down so the rest of the application can reclaim the resources. The places in Rust where exceptions are thrown are usually places where the programmer has chosen not to handle a logic error -- usually indexing out of bounds, integer overflows (sometimes), or forcing an optional value. Things that would be RuntimeExceptions (unchecked exceptions) in Java.