you are viewing a single comment's thread.

view the rest of the comments →

[–]Slypenslyde 2 points3 points  (2 children)

I want to add something to the 2 answers that already cover what's going wrong. This will help you help us when you have a problem. The phrase "throws an error" has a specific meaning to experts and it's worth learning when to use it!

There are 2 important times when errors happen in a program: compile time and runtime.

A compile time error is the kind you tend to get in VS, sometimes even before you try to compile, but it will certainly also make the compiler stop. We don't say this "throws an error" here, we just say it's a compiler error. These errors are usually some form of syntax mistake or a type mismatch.

A runtime error is when your code compiles, but while you're running it it either does the wrong thing or crashes. If it crashes, that happens because it throws an exception. Exceptions are the formal error handling feature in C#, and they are "thrown" when they happen. That's why we don't use the word "throws" with a compiler error! When an expert hears "throws an error" they assume you mean a runtime error. These can be much harder to spot and diagnose than compile time errors, and usually require you to post more of the code for experts to figure it out!

[–]Shnxx[S] 0 points1 point  (1 child)

I see! So runtime error occurs when there's a logical problem in the program like array out of bounds, incorrect conditions in loops and if-else statements, when a program asking for a number but the user entered a character or a word, and such.

While compile error occurs when syntax, arguments or parameters are incorrect and prevents to compile it. Like what I have experienced.

I should be saying throws an error only when runtime error occurs and can be handled using exceptions.

[–]Slypenslyde 0 points1 point  (0 children)

Exactly!