-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cell::setValueExplicit raises "Unhandled Exception" warning #3754
Comments
Not a PhpStorm user, so you'll have to do some detective work for me. First, I'll point out that using setValue(42); I'll get back to your original statement in a moment. If you use setValue, does the IDE accept that statement without warning? If it does, the difference between setValue and setValueExplicit regarding Exceptions is that the setValue doc block contains an |
Hello, thanks for taking a look.
This is in the context of a custom (simple) value binder, so I can't use setValue()
No, that raises the same warning. As far as I understand it, PhpStorm doesn't trust the doc block if there's no |
From the link to which you pointed, it seems like you can configure your own unchecked exceptions list. Can you not configure it to treat If you can't, I think you need to check with PhpStorm about what the "correct" solution would be here. In principle, I don't mind adding or changing the |
I could, but then the IDE wouldn't warn me about any
Of course, I agree. I think using |
|
Yes, it's used as a catch-all generic "Exception from PhpSpreadsheet" as far as I can tell
It doesn't raise any warnings from the IDE anymore
No.
No worries! |
Fix PHPOffice#3754. Because `PhpSpreadsheetException` extends `Exception`, PhpStorm warns that calls to `setValueExplicit` and `setValue`, among others, do not handle the exception, because PhpStorm treats `Exception`, by default, as "checked". On the other hand, PhpStorm treats `RunTimeException` as "unchecked" so won't flag such calls. It is reasonable to let `PhpSpreadsheetException` extend `RuntTimeException`, and will eliminate the problem, without having to wrap code in all-but-useless try-catch blocks (e.g. for `setValue`, the code would raise an exception only if you try to set the cell's value to an unstringable object).
Whoops, I didn't get a notification, sorry. I'll get to it as soon as I can, probably Monday |
I finally got composer to install the right branch and tested it. No more warnings, thanks! |
Fix #3754. Because `PhpSpreadsheetException` extends `Exception`, PhpStorm warns that calls to `setValueExplicit` and `setValue`, among others, do not handle the exception, because PhpStorm treats `Exception`, by default, as "checked". On the other hand, PhpStorm treats `RunTimeException` as "unchecked" so won't flag such calls. It is reasonable to let `PhpSpreadsheetException` extend `RuntTimeException`, and will eliminate the problem, without having to wrap code in all-but-useless try-catch blocks (e.g. for `setValue`, the code would raise an exception only if you try to set the cell's value to an unstringable object).
This is:
What is the expected behavior?
setValueExplicit
raises an exception like LogicException or similar, which are considered unchecked by most IDEsWhat is the current behavior?
IDE (PhpStorm 2023.2.2) warns about "Unhandled \PhpOffice\PhpSpreadsheet\Exception"
What are the steps to reproduce?
Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:
If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.
What features do you think are causing the issue
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
Yes
Which versions of PhpSpreadsheet and PHP are affected?
Using 1.29.0
The text was updated successfully, but these errors were encountered: