Empty Catches cause code errors & unreliability

[nz_btn text="Software Resiliency" link="http://casthighlight.wpengine.com/software-resiliency/" target="_self" animate="false" animation_type="ghost" color="black" size="small" shape="rounded" type="normal" hover_normal="fill" hover_ghost="fill" icon="icon-dashboard"][nz_btn text="Programming Best Practices" target="_self" animate="false" animation_type="ghost" color="black" size="small" shape="rounded" type="ghost" hover_normal="fill" hover_ghost="screen" link="http://casthighlight.wpengine.com/category/product/indicators-methodology/code-insights/software-resiliency/programming-best-practices/" icon="icon-code"]

Why you should care

When an exception occurs during programming, it is usually caught in a catch block. Empty catch is when an exception occurs but the program fails because nothing occurs. As a result, they are a common source for obtaining errors in the code, and then executing these errors. It is also inefficient since it catches nothing and executes nothing.

Business Impacts

Empty catch blocks are considered a risk from a business perspective as it can pose security issues. Risks can involve programmers and/or the company are unaware of the security being compromised. [nz_btn text="Security Risk" target="_self" animate="false" animation_type="ghost" color="pink" size="small" shape="rounded" type="normal" hover_normal="opacity" hover_ghost="fill" link="http://casthighlight.wpengine.com/category/product/indicators-methodology/risk/" icon="icon-office"]

CAST Recommendations

CAST Recommends enforcing a Style Guide for the company that strongly suggests avoiding the use of empty-catch blocks to solve a problem in the code.  Instead teams should be encouraged to collaborate and work on the problem together through communication.

References

https://stackoverflow.com/questions/1234343/why-are-empty-catch-blocks-a-bad-idea[nz_btn text="Style Guide" target="_self" animate="false" animation_type="ghost" color="turquoise" size="small" shape="rounded" type="ghost" hover_normal="fill" hover_ghost="fill" link="https://github.com/Kristories/awesome-guidelines" icon="icon-book"]

How we detect

This code insight shows that catching an exception provides robustness treatment or error management. A catch doing nothing can masks an error, allowing the program to pursue and ignore the problem.

Cloud Readiness

[nz_btn text="Versions & Deprecated Code" target="_self" animate="false" animation_type="ghost" color="juicy_pink" size="small" shape="rounded" type="normal" hover_normal="opacity" hover_ghost="fill" link="#"] Ineffective use of the provided stack: Having an empty catch in the program can mask errors that can misinterpreted when migrating to the cloud.

About CAST and Highlight’s Code Insights

Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.
[nz_btn text="See features" link="http://casthighlight.wpengine.com/outputs-analytics/" target="_self" icon="icon-stats" animate="false" animation_type="ghost" color="black" size="small" shape="rounded" type="normal" hover_normal="fill" hover_ghost="fill"][nz_btn text="How it works" link="http://casthighlight.wpengine.com/how-it-works/" target="_self" icon="icon-cog" animate="false" animation_type="ghost" color="black" size="small" shape="rounded" type="ghost" hover_normal="fill" hover_ghost="fill"]
For reference only. For the complete details please refer the original article
https://doc.casthighlight.com/alt_emptycatches-avoid-empty-catch-blocks-php/
Have more questions? Submit a request

Comments

Powered by Zendesk