Sobes.tech
Junior — Middle

What distinguishes a runtime error from a compile-time error?

sobes.tech AI

Answer from AI

A compile-time error occurs during the compilation stage of a program. These are syntax errors, type errors, missing references, and other issues that prevent the generation of executable code.

A runtime error occurs during program execution, after successful compilation. These can include exceptions, division by zero, array index out of bounds, memory access errors, and other situations that manifest only during runtime.

Example:

// Compile-time error:
int x = "string"; // cannot assign a string to an int variable

// Runtime error:
int[] arr = new int[3];
int y = arr[5]; // IndexOutOfRangeException during execution

Thus, compile-time errors prevent the program from running, while runtime errors occur during its operation.

What distinguishes a runtime error from a… - sobes.tech