13
1 Exception Handling, I/O Streams, and Applets

Exception handling.41

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Exception handling.41

1

Exception Handling, I/O Streams, and Applets

Page 2: Exception handling.41

2

Objectives

On completion of this period, you would be able to know:

• The sources of errors

Page 3: Exception handling.41

3

Recap

• In the previous classes, you have studied about • Packages • Interfaces• Multithreaded programming

Page 4: Exception handling.41

4

Source of Errors

• There are several types of errors, each with its own method of detection and repair mechanism

• The basic types of error are• Syntax errors• Runtime errors• Logic errors• Incorrect operator precedence errors• Threading errors

Page 5: Exception handling.41

5

Syntax Errors

• These are errors due to• Grammar • Punctuation such as mismatched quotes, missed

commas • Case-sensitivity issues

• These errors are caught by the javac compiler

Page 6: Exception handling.41

6

Runtime Errors

• These errors only show up as the program is executed

• A common example is division by zero

Page 7: Exception handling.41

7

Logic Errors

• These are basic errors in the programmer's algorithms or procedural errors

• Diagnosis only comes when incorrect results occur

• An example is wrong scoping of a variable

Page 8: Exception handling.41

8

Incorrect Operator Precedence Errors

• These are basic mathematical grouping errors• The best way to avoid them is with brackets to

force the grouping explicitly

Page 9: Exception handling.41

9

Threading Errors

• These errors can occur when multiple threads are programmed

• Common issues are access, deadlock, data race and synchronization

• These types of errors are very difficult to trace

Page 10: Exception handling.41

10

Discussion• List the common errors you encountered

• Spelling and typos• Brackets or quotes not matched• Wrong type of bracket. Each has its own use • Not using the escaper backslash when required• Un-initialized variables may be referenced

accidentally• Arrays bounds related• The type of the variable may be critical• Casting a variable can cause loss of accuracy• The scope of a variable can affect its current value

Page 11: Exception handling.41

11

Summary

• In this class we discussed various types of errors. They are• Syntax errors• Runtime errors• Logic errors• Incorrect operator precedence errors• Threading errors

Page 12: Exception handling.41

12

Quiz

1. Among the following types of errors which one is easier to correctA. Runtime errorsB. Syntax errorsC. Threading errorsD. Logic errors

Page 13: Exception handling.41

13

Frequently Asked Questions

1. Explain about various sources of errors