Why Exception Handling is Vital for Robust Code Error Handling Guide

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

I've always understood the case you're describing ("I can't handle this error and it won't allow me to meet the post-condition of this function") is the definition of an "exceptional" case.

accountname
Автор

i’m an errors-as-values kinda guy but i use the same approach

slipperynickels
Автор

An interesting use case for exceptions I found was in handling of data passed from an arduino microcontroller. The control flow relied on the state of the device, which could become desynced or disconnected, and throwing an exception when the data received no longer matched the format agreed upon, made it so the new logic could pick up as soon as it was needed and ready.

Cerafem
Автор

I'd say if the current function cant handle the situation at all, just throw.

mjKlaim
Автор

But the example you’ve used is something exceptional happening.

The problem that the rule tries to prevent is using exceptions to control flow. Like a method that throws an exception where it could return a Boolean and where handling of that exception is no different than an else statement (no logging and so on because it’s not really an exceptional case). People sometimes did this to avoid returning values from nested methods.

zlamanit
Автор

exceptions are unpredictable jumps in control flow and are and always have been none sense. Thats why most languages who can stay away from them. arguing about when and where to use a concept that is malformed is pretty fruitless.

gideonunger