3 ms·
> That's because Rust doesn't have exceptions, it has panics, they're not a general-purpose error-reporting or control-flow mechanism. Oh, that's another minus
by EugeneOZ 11y ago
> That's because Rust doesn't have exceptions, it has panics, they're not a general-purpose error-reporting or control-flow mechanism.
Oh, that's another minus: love to redefine well-known terms.
Panics are exceptions, they behave exactly as exceptions, just unhandled. All other is just casuistry
- masklinn 11y ago> Oh, that's another minus: love to redefine well-known terms. Panics are exceptions The point of calling them panic is so they're not interpreted as exceptions and people used to exceptions-as-an-error-reporting-mechanism don't try to use them so. > they behave exactly as exceptions, just unhandled The "unhandled" part is exactly why they're not called exceptions.
- EugeneOZ 11y agoRedefining well-known terms gives nothing except confusion. And https://github.com/rust-lang/rfcs/pull/243 https://github.com/rust-lang/rfcs/pull/243 is another step in this direction (beside "?" idea). If usual errors handling will be called "exceptions", then we will have full mess with "Exceptions" term in Rust.
- scott_s 11y agoI don't think they've redefined any terms. When someone says a language "has exceptions", I think most people assume they can be caught as a way to recover from errors. Rust's panics are not that, so they used a different term to avoid confusion.
- EugeneOZ 11y agoThat 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.