3 ms·
"Panic" and "exception" is literally the same thing. Sorry you were misled, but programming is, indeed, hard, and no, you can't go shopping instead.
by otabdeveloper4 4y ago
"Panic" and "exception" is literally the same thing.
Sorry you were misled, but programming is, indeed, hard, and no, you can't go shopping instead.
- Kranar 4y agoPanics and exceptions are not the same thing. For one, it's not possible to recover from a panic. You can handle a panic from within a handler before the program terminates, but you cannot resume execution as you can with exceptions.
- TazeTSchnitzel 4y agoYou can recover from a panic though? I don't think you're required to call resume_unwind after catch_unwind. The underlying machinery is the same as C++ exceptions, so there's no reason that wouldn't work. Obviously this is not something you're encouraged to do often, but there's applications where it might be reasonable.
- cornholio 4y agoA panic is an unrecoverable error caused by violating runtime invariants. A bug exists in the program and there is no (correct) way for the program to continue execution. For example, an array was accessed at index "-1". Exceptions are a particular technique for dealing with errors in general, that can be used for both unrecoverable and recoverable errors. They infamously trade programmer convenience for hard to understand bugs, fragile run-time behavior and unmaintainable code.
- otabdeveloper4 4y agoA distinction without a difference, because "panics" and "exceptions" are literally the same code under the hood of the compiler and standard library. Fragile run-time behavior and unmaintainable code is because programming is hard and cruft accumulates in the face of difficult requirements. Renaming a thing that traumatized you in the past won't make the cause of the trauma go away.
- milesedgeworth 4y agoAlthough the code generated might be similar, it's not a "distinction without a difference" because the language doesn't provide the same tools for interacting with panics as say C++ does with exceptions. There is no "try catch" for panics, you either catch them at the thread boundary or catch them with catch_unwind. Everything in the std lib is built with Result for errors that can be handled, not panic. Programming is hard, but that doesn't mean that certain language design choices don't have meaningful impact on what type of code becomes easier/harder to write. Other people are saying similar things, and I ask you listen to what they're saying, rather than talking about people being "traumatized" by a programming construct.
- otabdeveloper4 4y ago> you either catch them at the thread boundary or catch them with catch_unwind So exactly like C++ exceptions then?