Instructables

Tips on how to find errors in code (focused on DOS)

Picture of Tips on how to find errors in code (focused on DOS)
--EDIT--
Added an easy way to get the error message on step 1.

Hello fellow scripters or curious members, this is my guide on how to spot and fix errors in large, complex code.

This isn't exactly an instructable, as it doesn't teach you how to create something, so if you think there's a better way to communicate it, tell me and I'll do my best.

The basic motives for me to make this 'ible is that in almost every script that I make with DOS, I always make a mistake. So, naturally I began getting good at spotting mistakes, or at least finding out where they are. I wanted to share this knowledge to help anyone having troubles with errors and tedious mistakes within their code. Keep in mind that some of these tips can be used for other languages other than DOS.

Without further ado, let's get started!
 
Remove these adsRemove these ads by Signing Up

Step 1: Error Messages

Picture of Error Messages
The first thing I tend to do is run the code a few times, trying to gouge exactly what is making the error. Whether it be that a variable hasn't been defined, or I did a FOR loop wrong. The most helpful thing when trying this method is the error message just before the screen closes. In VBS and Python (I'm sure there's more than that), error messages are there in plane sight, in batch sometimes they are illusive. 

The point I'm trying to get across is that if you know what you're dealing with it's going to be a lot easier. For instance, if you're an electrician, and someone calls you saying something like "My light's not working", that's not a lot to go off. I'm not an electrician but I'm pretty sure there's a lot more than one possibility. The whole entire house's power could be off, and they only had the light on, so they thought it was only the light (very bad metaphor). 

Here's an easy way to get the error message if the window opens and closes too fast. Navigate to the folder containing the file through the command prompt (cd fiile_path), and then write something like...

start file 2> "error.txt"
start error.txt /WAIT
del error.txt


This will export the error message to a text file which will pop up, and once closed it will be deleted.

Well, I hope I'm able to be understood in my jabbering.

Next strategy!