What??!
For example, the statement byte b = 200; is syntactically correct but the compiler does not like it. The compiler knows
that the value 200 is too big to fit into a byte and it believes that the programmer is
making a logical mistake here.
You say compiler correct only syntactical errors not logical as JVM does.
Then you say that byte b = 200; is a logical error but IT IS NOT BECAUSE IT IS A SYNTACTICAL ERROR
[HD Pg 23, Sec. 1.8.3 - compilation-error-vs-exception-at-run-time]
Moderator: admin
-
- Posts: 6
- Joined: Tue Apr 23, 2024 3:03 am
- Contact:
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 23, Sec. 1.8.3 - compilation-error-vs-exception-at-run-time]
The complete paragraph prior to this line of code that you are referring to is this:
So where is the confusion??
So, the text quite clearly explains the issues involved. Compiler prevents all syntactical errors and also does prevent some logical ones (but not all logical errors, because it can't detect all of them).Besides being syntactically correct, the compiler wants to make sure that the code is
logically correct as well. However, the compiler is limited by the fact that it cannot
execute any code and so, it can never identify all the logical errors that the code may
have. Even so, if, based on the information present in the code, the compiler determines
that something is patently wrong with the code, it raises an error. It is this category of
errors that causes the most frustration among beginners.
So where is the confusion??
If you like our products and services, please help us by posting your review here.
-
- Posts: 6
- Joined: Tue Apr 23, 2024 3:03 am
- Contact:
Re: [HD Pg 23, Sec. 1.8.3 - compilation-error-vs-exception-at-run-time]
Compiler does prevent some logical ones but not all logical errors?
Can you give me 1 example of logical error the compiler prevent and 1 example of logical error the compiler doesnt prevent?
Can you give me 1 example of logical error the compiler prevent and 1 example of logical error the compiler doesnt prevent?
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 23, Sec. 1.8.3 - compilation-error-vs-exception-at-run-time]
Both are already given in the same paragraph:
byte b = 200; has a logical issue. There is nothing wrong with it syntactically. The value 200 cannot fit into a byte. The compiler notices that and refuses to compile.
int i = 10/0; also has a logical issue because an int datatype cannot represent infinity. But the compiler does not notice it and accepts the code as valid.
byte b = 200; has a logical issue. There is nothing wrong with it syntactically. The value 200 cannot fit into a byte. The compiler notices that and refuses to compile.
int i = 10/0; also has a logical issue because an int datatype cannot represent infinity. But the compiler does not notice it and accepts the code as valid.
If you like our products and services, please help us by posting your review here.
-
- Posts: 6
- Joined: Tue Apr 23, 2024 3:03 am
- Contact:
Who is online
Users browsing this forum: Google [Bot], PatriciaPecingina and 32 guests