In PyCharm debugging mode, is there way to let it stop right after it hits an error but not exit and highlight the offending line? The analogous feature I have in mind is "dbstop if error" of Matlab.
Yes, there is. Under Run, if you hit View Breakpoints (Ctrl + Shift + F8 on Windows) there's a checkbox where you can create an exception breakpoint for any exception.
The given answer was confusing to me. To do this you do not need to go to preferences, what you need to go is to break points menu bar (which is not in preferences for some reason). So:
Go to break point by pressing Command + shift + fn + F8 (Ctrl + Shift + F8 on Windows) or go to the breakpoints you have at the bottom (see picture 1). This opens the break point menu (see picture 2).
Then click enabled (for me suspend was already on so I only needed to click enabled). That's it.
Pic 1:
Pic 2:
Note: the reason this feature is useful is because after running an execution it halts with exactly the program state it caused it to err. For me I have stochastic code due to machine learning and reproducing the error exactly is annoying. I'd rather just see what cased the error, inspect the program state, stack etc and just fix it. There is even a little window at the bottom right to run code so I can test it right there while I am fixing it. I can even do control+shift+E to test pieces of code from my actual code (as I right new code).
Related
I know I can comment the code but would be even better if there is a shortcut to skip execution of code between two breakpoints.
VS has a feature 'set next statement' which moves the program counter to the to that location and continues execution from there (skipping anything in between). You can read more about it at: https://learn.microsoft.com/en-us/visualstudio/debugger/navigating-through-code-with-the-debugger?view=vs-2017#BKMK_Set_the_next_statement_to_execute. The easiest way to use it is to either use the context menu item "Set Next Statement" (right click on where you want to set it) or hold down the ctrl key which changes the green "Run to click" editor glyphs into yellow "Set next statement" glyphs and just click on where you want to set it.
Set next statement is a great tool but it's really dangerous as a debugging tool. You're using the debugger to execute code in a way which would never happen normally. The results of which could cause crashes or other failures easily. It's real easy to do things like skipping over the initialization of a variable that's later used and will now cause an exception/crash.
It can be used in JS, .NET and native.
I'm in VS2010, on a breakpoint. How can I cause a datatip to be displayed for a given variable/expression w/o using my mouse to hover it?
That can't be done, exactly, but you can get the same result by selecting the variable you want to watch (using ReSharper's Ctrl + Alt + →/← can speed this up), and pressing Shift + F9, which will raise "QuickWatch" modal window with the datatip contained within.
If you prefer, you can also go into Options->Keyboard and bind the Debug.AddWatch to a different keyboard shortcut, and use that instead of Shift + F9, and then your variable data will persist in the Watch window so you can come back to it later (as suggested here)
You can also do this by opening the command window (Ctrl + Alt + A) and typing Debug.AddWatch variable_name.
While you can pin multiple windows in VS it will be a somewhat cumbersome experience and you will have to over it.
I personally use visual studio plugin called Oz Code, that automatically annotates all the local variables and intermediate results so I don't have to chose which variables to pinpoint.
The results looks something like this:
Will adding a watch not be suitable? When you hit your breakpoint the relevant details of the variable will be shown in the watch window.
Perhaps I have misunderstood what you're trying to achieve here!
You can click the 'pin' icon to force any datatip to stay open, and it will update to the current contents when you hit the breakpoint.
I don't know of a way to open a specified tip without pinning it, however.
The Locals and Autos windows might be helpful as they show all local variables, (they even show the return value of called functions!).
Note however that they show directly only variables in scope, so if you need a detail property that it is not yet menotioned in the code you can drilldown using the →/← keys, however if it is already mentioned in the code in the current scope then you should be able to see it directly in the Autos window.
I was getting tired of hitting the F10 every step to debug the programs. Are there any program can automate the visual studio to run each debugging step in a consistent frequency? say, 3 seconds for each step?
Regards,
Sam
You can easily do that with a simple script in Autohotkey.
Download it from here: http://www.autohotkey.com/
Install Autohotkey.
Run it.
Find the green "H" icon in the task bar (bottom right).
Right click the icon and select Edit script.
And copy paste this script below.
^!y::
InputBox, input1, How many F10 strokes you want?, , , 250, 100
InputBox, input2, How many seconds between each F10 stroke?, , , 250, 100
if ErrorLevel <> 0
{
MsgBox, CANCEL was pressed.
}
else
{
loop, %input1%
{
Sleep, (input2 * 1000)
Send {F10}
}
MsgBox, "Your F10 script has Ended"
}
return
Then reload (again by right clicking the green "H" icon in task bar).
Press Control+Alt+y to try out the above script.
Sitting there repeatedly hitting F10 can be annoying, but you probably just need to make more use of the inbuilt debugging features.
set a breakpoint at a targetted location and hit F5 to run the program, it will stop when it hits the breakpoint
use F11 to step in to a function
use Shift-F11 to step out of a function
use the breakpoints window (Debug->Windows->Breakpoints) to get a complete list of all the bp's and you can easily enable/disable any of them (or set any of their other options)
use the Exceptions window (Debug->Exceptions) to select exceptions that you want to break on when they are first thrown
familiarize yourself with the options available to breakpoints (right-click on the bp itself to get these)
hit count: specify how many times code should go past the breakpoint before it stops
condition: super useful (i use it all the time), you can use almost any expression in there, including checking the value of inscope variables
when hit: you can run a macro when the breakpoint is hit
filter: to restrict which running thread can break on that breakpoint
The problem is exactly as asked in the question title.
When I'm typing in the text editor and referencing a public method that has a long signature (lots of parameters, usually 10 or more) the intellisense just stops working. It will sometimes flicker; other times it will not show at all.
Only seen this happen with C#, but I don't use anything else. It might happen in VB too. Don't know.
Anyone else seeing this?
I've Googled for an hour but can't seem to iron it out. I've restarted VS, rebooted the machine, enabled/disabled intellisense in Tools -> Options. NOTHING works.
You can hit CTRL Shift Spacebar to bring it back up.
Even better, Ctrl Shift Alt + C copies it to the clipboard.
Then Ctrl Shift Alt + P pastes it. Handy for templates.
I've discovered one cause for the problem.
If the method is at the top of the screen, it pops downwards.
If the method is at the bottom of the screen is pops upwards.
However in the middle of the screen if it's too big to go either way it gets confused - flickers or just won't open.
Unfortunately, no matter what I do I can't seem to get it to display more than 37 parameters...
Found a partial solution - change the font size
Was supposedly scheduled to be fixed in SP1...
http://social.msdn.microsoft.com/Forums/en/vseditor/thread/e2f06f24-0b68-48f3-a8b3-c31948f6e168
Is there any way to tell the debugger to just continue until the next file is accessed, and/or until the next (developer written) function is accessed, without setting debug points ahead of time? I'm kind of new to VS debugging so all I use right now are f5, f10, and f11.
There is currently no way to do what you are asking. The main ways of telling VS to go until something happens are the following
Hit F5 and VS will go until the next user breakpoint or ,depending on your settings and where it occurs, the next exception is raised
Right click and select "Run to cursor"
Shift-F11 breaks out of the current method
Run to cursor doesn't require an explicit break point but it does require that you know where you want to break next.
You can right-click and select "run to cursor" if you just want to run to a specific line ahead in the execution stream.
Another one is Shift-F11 which finishes the current method and breaks again when you get back to the caller.
Actually, there is a way to set conditional break points.
Click in the left margin on the line where you want to break, as usual. (or F9)
Right-click on the red dot. In the context menu, click on "Condition...."
In the dialog, set your condition, e.g., fileName == "foo"
Hit F5 and go until the conditional break is hit.
Looks like there's not a way to do what I wanted to do