Urgh... No exceptions in Rust annoys me. Now you only have the choice between "this didn't work please handle this error, thank you ^-^" and "you fool, prepare for annihilation". So basically if anything remotely serious happens your programs dead and there's nothing you can do about it. I don't get why people have this hate for exceptions. Everytime a new language gets made it's always either "ew it has exceptions" or "it's so nice it doesn't even have exceptions". NOOO! They can deal with serious situations in the best possible way and they can be statically checked (so no "but they're so complex and unpredicable" stuff please). If you can expect an exception they shouldn't be used in the first place (eventhough they are absolutely no less good than Option returntypes or whatever, just different) but in cases when it's impossible to predict an error they really shine. And not having them makes your language worse. If a device driver accesses illegal memory it should throw an exception, so instead of the computer shitting the bed, first the offending function has a chance to resolve the problem at it's root, then a few functions up the call stack, the general control functions of the device drivers can handle it and restart the operation if applicable, and even if the driver fails to handle it, the OS can jump in and restart the driver, log an error and do whatever. It's absolutely beautiful: This hierarchical ramp from near the accident site to more high level operations code ensures the error can be caught at the right level of abstraction without introduction a lot of boilerplate. If everything fails and nobody can handle it *then* the program or kernel or whatever can panic.

  • 2
    Like you said, exceptions are for unexpected, everything else is an error and should be dealt with immediately. Now like 99% of the time you expect to get an error, rest 1% of cases are almost never encountered, but most languages still provide very basic exception mechanism (don’t know in case of rust though).

    The reason why exceptions are evil is because they are misused for above reason. They are used for error handling when they shouldn’t. Now let’s say you have huge application, every exception got so abstracted, they got scattered everywhere, there is no central error handling anymore, because it’s everywhere and nowhere. Then someone finally thinks that some exception is not necessary to be thrown and program can continue working without it, so they catch it and allows application to continue running. Even worse scenario that exception doesn’t have it’s own instance and is global, oh boy then shit could go wrong in that case.
  • 3
    To sum up, exceptions promotes bad design and thus should be avoided, instead errors should be handled immediately, either it’s by printing and terminating everything right away or passing that error to other function. You say that’s a lot of boilerplate code? That’s right, but at least it’s maintainable.
  • 0
    @SevenDeadlyBugs Error return codes or sum types or however it is handled else isn't better than exceptions. Exactly the same argument could be made for them: "It's annoying so people just ignore it by relying on getting the right type and panic'ing else."

    There's no difference between checked exceptions and explicit error handling. The only difference is that exceptions *also* work for cases where error handling isn't possible otherwise. It's just a design decision and if people decide that normal error handling looks better or is more intuitive or whatever then fine, but you still need exceptions
  • 0
    @SevenDeadlyBugs People complain about Java exception handling being annoying. You know why they added the expect method to Result in Rust? Because people don't want to deal with error handling. Again, the difference is not quality of error handling but a lack of functionality
  • 0
    So why work with language/stack you don’t like?
    If it’s for money, start looking for another job in a stack you want to.
  • 0
    @NoToJavaScript I do like Rust, that's why this annoys me so much. I even wanted to use it for some hobby os dev'ing but that seems to not be happening anymore sadly
Add Comment