DEV Community

Bhavish Reddy
Bhavish Reddy

Posted on

Steps For Troubleshooting your Code

Hi Everyone you might have faced many troubles while writing code and you got that error many a times while learning!

Let's try to find that error!

Follow the steps below, I'm sure you're gonna make it! 💪👩‍💻

1. Indent your code

Some programming languages may not require indentation to work properly, but it is always recommended to indent your code properly while finding the errors in the code you can understand better, what's happening with good organisation of code.

You can easily find the missing parentheses, if any causing errors.

2. Verify the variable names

Some times we may have declared the same variable name twice or even better we might have missed the scope of the variable we are using. So it's better to have a look at variables.

Also name the variables descriptively, that it's easy to understand what it does and makes our process of finding bugs easy-peasy 🙂

3. Test the code with different inputs

It's really important to test our program with different inputs to understand the program flow better and to find out what's that tiny case that's causing the program to break. If you're writing test cases don't forget to write test cases with all the possible inputs to find the case where our program simply doesn't work!

4. Log the values of critical variables

By this time you may got some idea by following the previous steps, now log or print the values of variables and check whether the value of variable is as expected or not.

I bet by this step you'll have probably figured out what that tiny little bug is.

5. Verify initialisation of variables

This is where most of the programmers fall prey and don't forget to initialise the variables ever.

This is quite critical and causes NullPointerException.

6. Focus on Stack Trace

If there is an error thrown, focus on the stack trace of the error where it shows the methods involved in causing the error and then go and squash the error.

7. Use Debugger on your IDE

Create break points wherever you doubt and then run the program and check it out to find the bug.

I'm sure by this step you'll successfully resolve your bug or error.

Last Note:

As the code complexity grows it will become too tough to find mistakes and resolve them, so do it step by step while building code.

Now let's go 🏃‍♂️ and quash that bug 🐞

Top comments (1)

Collapse
 
jpchreim profile image
Jean Pierre Chreim

Thanks for the tips buddy!!