0% found this document useful (0 votes)
36 views3 pages

Types of Errors: School of Computer Science & Information Technology

The document discusses different types of errors that can occur when programming in Java, including syntax errors, semantic errors, compiler errors, and runtime errors. It provides examples of specific compiler errors like "cannot resolve symbol" and "cannot find class file". Runtime errors discussed include exceptions like NullPointerException, ArrayIndexOutOfBoundsException, and NoClassDefFoundError. The document emphasizes that compiler errors provide the file name and line number to help locate the issue, while runtime errors may be due to logic errors and only occur when the program executes.

Uploaded by

Alen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Types of Errors: School of Computer Science & Information Technology

The document discusses different types of errors that can occur when programming in Java, including syntax errors, semantic errors, compiler errors, and runtime errors. It provides examples of specific compiler errors like "cannot resolve symbol" and "cannot find class file". Runtime errors discussed include exceptions like NullPointerException, ArrayIndexOutOfBoundsException, and NoClassDefFoundError. The document emphasizes that compiler errors provide the file name and line number to help locate the issue, while runtime errors may be due to logic errors and only occur when the program executes.

Uploaded by

Alen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

School of Computer Science &

Types of Errors
Information Technology
 Syntax errors
 Mistakes in the rules of the language itself
 Illegal Java - errors of grammar or punctuation
G6DICP - Lecture 6
 Semantic errors
 Mistakes in the logic of the code
Errors, bugs and debugging  Legal Java - but not what you intend!

Where errors show themselves Compiler Errors


 Compile-time errors  If javac gives no output, the compilation is successful
 Many syntax errors are detected by the compiler
C:\code javac fname.java
 The compiler will generate an error message - error: cannot read: fname.java
including a line number 1 error
C:\code
 Run-time errors
 Some syntax errors are detected by the VM when the
program is run  Cannot read… compiler error
 This means that the source file (fname.java) has not been read.
 Legal Java - that causes problems under certain
 Usually a typo in the file name or javac command
conditions.
 Remember Java is case sensitive!
 Logical errors  Could be file privileges
 Unexpected results - bugs!
3 4

Compiler Errors (2) Compiler Errors (cont.)


 Most compiler errors have a file name and line number  Most compiler errors have a file name and line number
 This tells you where the error was detected  This tells you where the error was detected

File name (fname.java)

C:\code javac fname.java C:\code javac fname.java


fname.java:23: cannot resolve symbol fname.java:23: cannot resolve symbol
symbol : class string symbol : class string
location: class fname location: class fname
string msg; string msg;
^ ^
1 error 1 error
5 6
Compiler Errors (cont.) Compiler Errors (cont.)
 Most compiler errors have a file name and line number  Most compiler errors have a file name and line number
 This tells you where the error was detected  This tells you where the error was detected
Line number (23)
Type of error

C:\code javac fname.java C:\code javac fname.java


fname.java:23: cannot resolve symbol fname.java:23: cannot resolve symbol
symbol : class string symbol : class string
location: class fname location: class fname
string msg; string msg;
^ ^
1 error 1 error
7 8

Compiler Errors (cont.) Compiler Errors (cont.)


 Most compiler errors have a file name and line number
 Most compiler errors have a file name and line number
 This tells you where the error was detected
 This tells you where the error was detected
Details of error Type of error Location of error

C:\code javac fname.java C:\code javac fname.java


fname.java:23: cannot resolve symbol fname.java:23: cannot resolve symbol
symbol : class string symbol : class string
location: class fname location: class fname
string msg; string msg;
^ ^
1 error 1 error
9 10

Compiler Errors (3) Runtime Errors


 The point at which the error is detected is not  Runtime errors occur while the program is running,
always the point at which there is a mistake in although the compilation is successful
the code  Usually runtime errors consist of “exceptions” in a thread
 Errors in the main method, generate exceptions in thread “main”
 For example unbalanced braces cannot be
detected until the braces are closed Exception in thread "main" java.lang.NoClassDefFoundError: fname

 Compiler errors can have knock-on effects, with  NoClassDefFoundError


other “spurious” errors being caused by the first  Caused if the interpreter can’t find the named class file
 ADVICE - fix the first compiler error, and attempt to (e.g. fname.class)
compile before looking at others - they might  This is usually a typo - either in the command line, the class
declaration or the file name
disappear!
 Remember Java is case sensitive!

11 12
Causes of Runtime Errors Exceptions
 Errors that only become apparent during the course of  When a potential error condition occurs while a
execution of the program program is running an Exception occurs
 External Factors - e.g.  For example attempting to read from a non-existent
 Out of memory file
 Hard disk full  Exceptions are of specific types - e.g.
 Insufficient i/o privileges  ArithmeticException
 etc.
 IOException
 Internal Factors - e.g.  ArrayIndexOutOfBoundsException
 Arithmetic errors
 Attempts to read beyond the end of a file
 If the program contains code to handle the
 Attempt to open a non-existent file
exception that code is triggered.
 Attempts to read beyond the end of an array  If there is no code to handle the exception then
13
 etc.
14
the program terminates with a runtime error

Missing Class File Null Pointer Exceptions


 This can be either a compiler error or a runtime  These are generated if your program atempts to
error! access something non-existent in memory
 If a class file used by the program is missing at  Internally these are drastic, but they can be
compile time, then a compiler error is generated triggered by extremely subtle errors
 If the program is successfully compiled, but a  They do not always provide a line number (or
class file is missing when it is run, then a run- that line might not be where the error is)
time error is generated  They can be extremely hard to debug
 NoClassDefFoundError

15 16

Logical Errors Debugging


 The program compiles and runs, but it doesn’t  Paper helps - examine your flow charts
do what is intended  Code tools
 May be caused by:  Flags - code that tells you where you are in a program
 Some syntax errors (i.e. legal Java that  Breaks - code that stops the program
is wrong in the current context)  Watches - code that prints the contents of variables
 Errors in logical design  Debuggers
 These are “bugs”  Software that implements the above
 Term coined by Admiral Grace  Also runs code visually in “slow motion”
Hopper for anything that causes
 Built into most integrated development environments
a program to do something
unexpected  Invaluable for debugging large, complex programs
17 18

You might also like