Bring exceptions under control
PhpStorm 2017.3 introduces several useful inspections and the corresponding quick-fixes for handling exceptions in your code.
Situations where executing your code will lead to a Fatal Error should be detected in advance and avoided. The new Unhandled exception inspection will help you with this by reporting exceptions that are not enclosed in a try-catch block, or that are not documented using the @throws tag. You can resolve the reported issues by using the provided Add @throws tag and the Surround with try-catch quick-fixes:
Redundant @throws tag
When refactoring your code, it’s always a good idea to make sure that your changes are reflected in the PHPDoc block.
In earlier releases, the Missing @throws tag(s) inspection checked that all the exceptions thrown by a function had been documented. The new Redundant @throws tag inspection serves the same purpose, though by doing exactly the opposite: it detects tags for which no exceptions are present in the function, and suggests removing them.
Using the corresponding Remove @throws tag and Update PHPDoc Comment quick-fixes, you will clean up your PHPDoc in a breeze:
Redundant catch clause
The new Redundant catch clause inspection will detect the situations in which the exception you are trying to catch is actually never thrown. Use the the corresponding Delete catch clause quick-fix to remove redundant catch blocks:
We hope that the new inspections will save you precious time and streamline your work with exceptions handling. If you need to customize the inspections’ severity level or define the scope they are applied to, navigate to Settings | Editor | Inspections and explore the PHP | Error handling and PHP | PHPDoc sections in the inspections list.
Your JetBrains PhpStorm Team
The Drive to Develop
Subscribe to Blog updates
Thanks, we've got you!
Qodana Clone Finder: Early Access Program
In December 2020, we announced the EAP for Qodana, which is rapidly evolving into a comprehensive platform that allows companies to perform multi-level evaluations of the quality of code they own, contract, or purchase. Qodana helps you detect bugs without relying on an IDE, either on a local machi…
PhpStorm 2020.2 EAP #3
The Early Access Program for PhpStorm 2020.2 is in full swing and today we’ve got the third build of the 2020.2 EAP for you. In this blog post, you can read about improvements for Git installed in WSL2 and Search Everywhere. Download PhpStorm 2020.2 EAP (more…)…
PhpStorm 2019.3.3 Preview
We’ve just rolled out a preview for the third minor update for PhpStorm 2019.3. Please give the PhpStorm 2019.3.3 Preview build 193.6494.5 a try and share your feedback with us. (more…)…
How to Upgrade to PHP 7.4 with PhpStorm
Check out our fresh video with a few nice tips and tricks on how to update your codebase to PHP 7.4. It combines materials from the PhpStorm 2019.2 and PhpStorm 2019.3 releases, with a few cool bonuses to boot. Nikita drew our attention to the fact that setters are slower than assigning prop…