How to disable warning for specific exceptions? - laravel

I do get a warning whenever I throw an exception in my code without explicitly stating it in the docblocs:
I know this can be fixed by adding #throw tags, but the warning is actually not 100% true, as I do handle the exception in /app/Exceptions/Handler.php. I would like to disable the warning for this single exception. Is this possible in PHPStan? I have not found anything in the docs, but in this blog post https://phpstan.org/blog/bring-your-exceptions-under-control it seems that one can have unchecked & checked exceptions, and I believe unchecked exceptions do not need to be declared. However, marking my exception unchecked in phpstan.neon does not get rid of the error:
exceptions:
uncheckedExceptionClasses:
- 'app\Exceptions\AuthenticationException'
I also noticed that the Symfony\Component\HttpKernel\Exception\NotFoundHttpException exception does not trigger the warning. I am not sure why, but it seems there is already a set of exceptions where no #throw is needed.
How can I suppress the warning for my exception?

As Bob has correctly stated this comes from PhpStorm itself and not PHPStan.
You can add any exception to the Unchecked Exception list so it will be ignored by PhpStorm at Settings/Preferences | PHP | Analysis
https://www.jetbrains.com/help/phpstorm/php-missing-throws-tag-s.html
As to why Symfony\Component\HttpKernel\Exception\NotFoundHttpException is not reported -- they have different parents:
NotFoundHttpException extends HttpException extends \RuntimeException (which is in unchecked list)
AuthenticationException extends \Exception

First of all, this is a PhpStorm hint, not a PHPStan.
The point of #throw in docblock is to show you what exceptions your method can throw. If another developer or yourself reuses that method elsewhere, PhpStorm will immediately remind you of that exception and suggest you either wrap it in try-catch or move it to docblock for higher-level processing.
So I see no problem pointing this exception at #throw.

Related

Persuade Visual studio not to break on unhandled exceptions

I want to run some code in debug mode. I do NOT want VS to break on any exceptions. My attempts to persuade it not to are failing. In particular, I unchecked every box under "Break When Thrown" in the "Exception Settings" window. What else do I need to do?
According to this documentation we can know that try-catch or try-catch-finally blocks are used to handle thrown exceptions.
You can use try-catch to handle the thrown exceptions like this:
try
{
throw new InvalidOperationException();
}
catch (Exception e)
{
Console.WriteLine("Cannot determine location type from provided inputs.");
}
Refer to this link we can know that uncheck the exceptions in Exception Setting just work for handled exception.
If you checked the exceptions in Exception Setting, the handled exception will also throw an exception and break the debug.
Uncheck or check exceptions in Exception Setting is invalid if you just throw an exception without handling it.
Unless you want to go for a try-catch solution.
Try this:
In Debug->Exceptions dialog, uncheck the check box under the User-Unhandled column for whatever exception type you wish to eliminate, for example: Common Language Runtime Exceptions, and VS will stop breaking on these exceptions.

how to change default message toomanyattempts

I am using prompts. When user types invalid option too many times, simulator throws an exception :
too many attempts
I tried with try and catch statement but exception message shows again.
Any idea ?

Intellij isn't breaking on uncaught exceptions

I'm getting a NullPointerException while writing Clojure in Intellij. When trying to debug it, Intellij is refusing to break when the exception happens.
Here's a screenshot that sums up the situation:
Note in the breakpoint manager on the left, I have a breakpoint set for NullPointerExceptions to fire when an uncaught exception happens. On the right, you can see that despite this breakpoint being set, a NPE is still managing to get through. I know from the rest of the message I seem to be trying to cast a null/nil to a double, but without a stack trace that's only so helpful.
If I check "Caught exception" it fires, but then I have to sift through a ton of NPE's that are happening internally that don't have anything to do with my problem. If I make it more general and ask it to break on any uncaught exception, it still refuses to break.
I don't think including code is necessary since I don't expect anyone to actually debug it for me; I'm more curious as to why it's not breaking when I expect it to.

How to watch for UNHANDLED exceptions only using WaitForDebugEvent family functions?

I'm trying to catch unhandled exceptions in the application and restart it on them using WaitForDebugEvent function. But I can't tell when exception is handled by application (try..catch for example) and when is not. How do I do that? There seem to be no such data in DEBUG_EVENT structure.
If your not catching certain exceptions using WaitForDebugEvent, you might want to try injecting an UnhandledExceptionFilter as well. other than that, check that your processing matches Microsofts Example
In the EXCEPTION_DEBUG_INFO structure, which is in the DEBUG_EVENT structure, there is a field dwFirstChance:
If the dwFirstChance member is nonzero, this is the first time the debugger has encountered the exception. Debuggers typically handle breakpoint and single-step exceptions when they are first encountered. If this member is zero, the debugger has previously encountered the exception. This occurs only if, during the search for structured exception handlers, either no handler was found or the exception was continued.
So you will want to look for times where dwFirstChance is 0.
But if you just want to restart your app when it fails, it might be easier to create another app to watch for the failure of the first one, rather than using the Windows debugging api.

DirectWebRemoting errors

I am supporting an application that has some DWR components. Whenever there is a server error i get a javascript alert that simply says 'error'.
Does anyone know where this might be configured and if there is a way to disable this. Id rather it silently fail at whatever then do this very distracting message.
Use DWR exception handlers in the positions wherever there is a chance for run time errors.
Use try catch mechanism and printstacktrace() in catch block. It works for me!

Resources