![]() ![]() In Visual Studio, you enter debugging mode by using F5 (or the Debug > Start Debugging menu command or the Start Debugging button It also allows you to pause the app at any point to examine its state and then step through your code line by line to watch every detail as it happens. When you run an app within a debugger, also called debugging mode, the debugger actively monitors everything that's happening as the program runs. A program might also terminate unexpectedly without telling you why. When you normally run an app, you see errors and incorrect results only after the code has run. Step through your code in debugging mode to find where the problem occurred You might also reduce the time it takes to fix a problem. Then, you can modify or add code incrementally, testing at each point for errors.īy questioning your assumptions, you can reduce the time it takes to find a problem in your code. When writing code, start small and start with code that works! (Good sample code is helpful here.) Sometimes, it is easier to fix a large or complicated set of code by starting with a small piece of code that demonstrates the core task you are trying to achieve. If it's not your code, it's possible you might need to spend time learning exactly what the code does before you can debug it effectively. (After you examine the API call in the debugger, fixing it can require a trip to the documentation to help identify the correct API.)Īre you using an API correctly? Maybe you used the right API but didn't use it in the right way.ĭoes your code contain any typos? Some typos, like a simple misspelling of a variable name, can be difficult to see, especially when working with languages that don’t require variables to be declared before they’re used.ĭid you make a change to your code and assume it's unrelated to the problem that you're seeing?ĭid you expect an object or variable to contain a certain value (or a certain type of value) that's different from what really happened?ĭo you know the intent of the code? It's often more difficult to debug someone else's code. You might have a long list of possible assumptions! Here are a few questions to ask yourself to challenge your assumptions.Īre you using the right API (that is, the right object, function, method, or property)? An API that you're using might not do what you think it does. Hidden or unknown assumptions can get in the way of identifying a problem even when you're looking right at the cause of the problem in a debugger. ![]() By stepping through the code in a debugger, you can examine each and every change to your variables to discover exactly when and how incorrect values are assigned.īefore you investigate a bug or an error, think of the assumptions that made you expect a certain result. If something else happened, what is the symptom of the problem? Do you already suspect where this problem occurred in your code? For example, if your code displays some text, but the text is incorrect, you know that either your data is bad or the code that set the display text has some kind of bug. A debugging tool can take you to the exact place in your code where the exception occurred and can help you investigate possible fixes. If you run into an error (exception) while running your app, it can be a good thing! An exception is an unexpected event encountered when running code, typically an error of some kind. We expect that you already ran into a problem in your code, otherwise you wouldn't be here trying to figure out how to debug it! So, before you start debugging, make sure you've identified the problem you're trying to solve: It helps to clarify the problem that you ran into before you try to fix it. Clarify the problem by asking yourself the right questions ![]() In this article, we introduce the core principles of debugging and provide tips to get you started. Using a debugger effectively is also a skill that takes time and practice to learn but is ultimately a fundamental task for every software developer. You then understand what corrections you need to make in your code and debugging tools often allow you to make temporary changes so you can continue running the program. Debugging means to run your code step by step in a debugging tool like Visual Studio, to find the exact point where you made a programming mistake. Sometimes it does something completely different! When the unexpected happens, the next task is to figure out why, and although we might be tempted to just keep staring at our code for hours, it's easier and more efficient to use a debugging tool or debugger.Ī debugger, unfortunately, isn’t something that can magically reveal all the problems or “bugs” in our code. Without fail, the code we write as software developers doesn’t always do what we expected it to do. Applies to: Visual Studio Visual Studio for Mac Visual Studio Code ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |