Get startedGet started for free

Graceful exception handling

1. Graceful exception handling

Graceful degradation is a process by which we adapt data to a specific value if it triggers an exception. You should only use graceful degradation when you are confident that it will not distort your data in a manner in which it is no longer useful.

2. Graceful degradation in action

Remember our example earlier where I tried to set the quantity below zero for a cookie because I got hungry and lost count of how many I ate? Let's take a look at how graceful degradation would work for that use case. Looking at the code, it is in our standard pattern except for after recording the check_violation error; I issue an update statement to set the quantity to zero and record another message that I made that adjustment to the record.

3. When to use graceful degradation

Remember, because you are fundamentally altering data, this is a potent and dangerous approach when not given the proper forethought about the use case. So when should you use this? Some good use cases are loading data from an external system where you want to replace nulls with 0s or getting readings from an instrument that is only accurate up to a certain threshold. Additionally, maybe you are receiving dates that are out of bounds that you want to set to some sentinel value, which is a value that you use to alert you to the data being changed that you can check for in later processing, or you want to write all records that cause exceptions to another table for further processing while allowing other operations to continue. All of these are solid examples of where you want to adjust the data to fit your need, for which grace degradation is perfect.

4. When to consider using graceful exception handling

Additionally, there are some places where using graceful degradation handling maybe a good idea; however, be certain to check out it affects the outcome your seeking before leveraging it. Two common cases are when the value change would be hidden insight of a math operation such as a sum, average or other aggregate. Also, take care that you ensure that graceful degradation when applied to trends or time series data doesn't skew your outcomes in a way that invalidates your data experiment or operations.

5. Let's practice!

When used judiciously, graceful degradation is a fantastic tool for reshaping data during processing. Let's apply ourselves.