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 ?
Related
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.
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.
I'm having a spring-mvc project set up with spring-roo, that runs on tomcat.
After setting up spring-security, I can not see exceptions/stacktrace in the console anymore...
I just go to the login page and try to login. In my UserService (that is called during the login process) I throw a NullPointerException to "test" this.
The Exception is not shown in the console. The only thing I can see, is the message of the exception on the login page (/login?login_error=t) like "Your login attempt was not successful, try again. Reason: blablabla".
That is not good, because I want to be able to see (in console) what is going on an where the problem is.
I commented out the filter 'springSecurityFilterChain' that was added when setting up spring-security.
When I throw an exception within a controller, the exception is shown in console as expected. So my guess is, that something handles the exception during the Filter chain and does not print it to the console. I wasn't able to find out, how to avoid this...
Any help would be appreciated!
Thanks
Yes you are correct, spring-security is taking care of the authentication part, so all you need is set the log level of spring-security to DEBUG
org.springframework.security.level=DEBUG
This should print all the exceptions which are occurring while authenticating.
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.
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!