Compiler versus Runtime Errors

Oh, how we love’em!

Errors are what make programmers, programmers; and what make non-programmers, quit!

We’ve all been there… What. I don’t understand. It doesn’t make sense. Throws up hands, and maybe flip a keyboard, chair, or table.

We can start with the beginning. The first error, we typically encounter is a compilation error. Also known as a syntax error, this error prevents the application from ever executing and fails during the compilation of the application. The compiling process, also known as the building process, tries to translate the programming language code down to system code to prepare the application to be executed either by a system or user. Some of our most common errors are the notorious semi-colon “;”. Typically, we just forget to add it at the end of the line. Another one is the closing curly-bracket ‘}’. Often times, curly-brackets are nested and in haste, we forget to appropriately close it out.

public class Program{
  public static void Main() {
    Console.WriteLine("Hello World")
  }
}

See if you notice the error above. It’s pretty straight forward, but very common. Now most IDEs provide hints to help prevent and minimize compiler errors.

Once you get pass the syntax error, there’s a chance your application fails or blows-up due to an error once it gets pass compiling and attempts to actually run. These errors are called, runtime errors. These errors are typically due to upper and lower bounds, type casting, or situations that are not always easy to detect by programmer or compiler.

public class Program{  
  public static void Main() {    
    string helloWorld = "Hello World!";
    Console.WriteLine(helloWorld);
    int willThrowRuntimeError = Convert.ToInt32(helloWorld);
  }
}

Do you see the error? Again, the syntax all looks good but the request that is being requested.

Lastly, I’ll briefly touch on the infamous Logic Error, because it is extremely common version of a run-time error, but requires extra testing and evaluation. The code compiles, it runs fine, but the output is not what you expect. Here’s an example below.

public class Program{
  public static void Main() {
    int startLoop = 11;
    int endLoop = 1;
    int counter = 0; 
    for (int i = startLoop; i < endLoop; i++){
      counter = counter + 1;
    }
    Console.WriteLine("Output: " + counter)
  }
}

As I come across some additional common errors, I’ll start to add entries for those as well.

Let me know your thoughts, and share some of your favorite errors.

dalain

About dalain

Dalain is a Technical Program Manager, entrepreneur and speaker that specializes in Technology for Businesses, STEM, StartUps, and Economic Development. As well as running a business and writing, he spends time volunteering in the community, supporting Black Businesses, listening to underground hip hop, and helping those in need.