What to do first when the application encounters an error
Question:
What do you do first when the application encounters an error? (Testing debugging ability and logical thinking.)
Answer:
-
First, I log the application’s execution flow to figure out which block contains the error.
-
I divide the code into blocks and check them one by one. For example, if I have 3 blocks and 2 are correct, the bug is probably in the remaining one.
-
After I find the faulty block, I add more detailed logs. When the app runs, those logs show how the code moves step by step, which makes it easier to spot where the logic goes wrong.
-
This helps me narrow down the bug. It could be a logic error or a race condition, where two blocks run in parallel and one finishes earlier than expected.
Things to avoid when debugging:
-
Reading the entire codebase at once. That makes it easier to miss small, hard-to-spot errors and gets tiring fast.
-
Relying on theories that are really just unverified guesses.
-
Fixing errors immediately without understanding the original bug, which can create new ones.
-
Not logging. If you do that, you lose visibility into how the code actually runs.