Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS12230 Introduction to Programming Lecture 6-2 –Errors and Exceptions 1.

Similar presentations


Presentation on theme: "CS12230 Introduction to Programming Lecture 6-2 –Errors and Exceptions 1."— Presentation transcript:

1 CS12230 Introduction to Programming Lecture 6-2 –Errors and Exceptions 1

2 Errors Three kinds: Compiler – missing ; – Don’t recognise a variable or class name Run time – Something happens as you run – Often null pointers Logic – The program runs but not ‘right’ 2

3 Some run-time errors can be ‘caught’ When reading from a file do you remember ‘throws IOException’ which propagates up the calling sequence? This is sort of like saying that you recognise your code may have a problem Instead, You can ‘catch’ exceptions and deal with them: try{ //piece of code that might cause exception } catch (IOException e) {//or whatever exception //some code to fix problem } 3

4 Look at the code in 6-week6 BadApplication (next slide) and Application Also summing etc. 4

5 5

6 Some run-time errors cannot and should not be caught They should be fixed instead One really common one is ‘NullPointerException’ That means that you are trying to call a method on an object that doesn’t exist For instance, in the code on last slide comment out staff=new ArrayList (); and see what happens 6

7 How to debug your code Three kinds: Compiler errors – usually not too hard with experience Run time – Try stopping execution just before the error Logic – Run line by line (in debugger or on paper) Show the links on the web site (other resources) http://www.aber.ac.uk/~dcswww/Dept/Teaching/CourseNotes/2012-2013/CS12230/resources.htm 7

8 At 3pm Go on with adding ArrayLists to the Monsters project 8

9 Tomorrow I will hand back the test and talk about it at 3pm. Also answer any questions you have on the assignment – make sure you read the 6-3 slides if we don’t do them in class No 10am lecture (so I can finish the marking) 9

10 Next week is ‘work week’ No CS lectures or Monday lab (demonstrators may be there) tutorials –you may persuade your leader to help you during that slot Yes, Wednesday and Friday practicals This is your big opportunity to get caught up on reading (how many of you have looked at the notes?) and practicals … … and make good start on assignment I may be away for part of it but answering email 10


Download ppt "CS12230 Introduction to Programming Lecture 6-2 –Errors and Exceptions 1."

Similar presentations


Ads by Google