I’ve been having a mid life crisis trying to figure out the difference even though I do get the gist of it but when it’s applied to examples I can’t seem to look at code and be like “oh yeah, runtime error” or “oop syntax error!” and I would just like to know how other people think about it to try to help my understanding more. Also is compile error the same thing as syntax error?
Compile Time vs. Runtime Examples Cheat Sheet?
java - What is the difference between run-time error and compiler error? - Stack Overflow
Are logic errors and run-time errors the same thing?
Difference between runtime error and syntax error
I know the difference between compile time and runtime errors, but does anyone have a cheat sheet, flashcards, free training resources, etc. specifically focused on being able to identify whether specific code will cause a compile time or runtime error? This was part of several questions on a test that I took previously and will need to retake and would love some good resources to memorize this or learn easy rules of thumb that will help identify which error would come up. This is a written test with no other resources available, so I cannot just test the code to see if it compiles. I'm pretty new to all of this, so please excuse me if I worded anything incorrectly. Thank you!
A run time error will only occur when the code is actually running. These are the most difficult - and lead to program crashes and bugs in your code which can be hard to track down.
An example might be trying to convert a string: "hello" into an integer:
string helloWorld = "hello";
int willThrowRuntimeError = Convert.ToInt32(helloWorld);
The compiler may not see this as a problem but when run an error will be thrown.
Compiler errors are due to inaccuracies in code, where the compiler throws an error to alert you to something which will not compile, and therefore cannot be run.
An example of a compiler error would be:
int = "this is not an int";
A runtime error happens during the running of the program. A compiler error happens when you try to compile the code.
If you are unable to compile your code, that is a compiler error.
If you compile and run your code, but then it fails during execution, that is runtime.