Vet Clinic Exercise Not in notes
What is cheating, again? ● We encourage you to talk to fellow students about assignments but you must write your code individually . ● Good rule of thumb: if you don't take notes during a Not in notes discussion about assignments, the code you write is truly your own. ● If you didn't write your code yourself from scratch, you're cheating. ● The consequences of getting caught are significant and not worth the risk: grade of 0 for course, reprimand on official transcript, etc...
Unit 10 : exception handling and file I/O Not in notes Today : broad overview of exceptions and try-catch blocks (don't worry about the details) Friday : More details about exceptions, and we begin File I/O...
Computer Science is... Data Mining Extracting patterns from huge amounts of data. Not in notes ● Statistical analysis ● Data collection and pre-processing ● Used for marketing, fraud detection, scientific discovery. (Web 2.0 companies are ● Privacy concerns! really into data mining.)
We have caused lots of exceptions so far in this course Exception in thread "main" java.lang. NullPointerException Not in notes at VetClinicTest.main(VetClinicTest.java:7) Exception in thread "main" java.lang. ArrayIndexOutOfBoundsException : 2 at VetClinicTest.main(VetClinicTest.java:8)
Exceptions can be “thrown” in at least 2 ways ● You do something silly in your code so that your program crashes ● The user of your program does something Not in notes silly so that your program crashes. ● e.g. You ask them to enter an int and they enter a letter.
There are several ways to deal with exceptions ● Fix your code so that the exception can't possibly occur anymore ● This is what we have been doing so far. Not in notes ● Describe what your program should do if an exception occurs by adding a try/catch block to your code.
Good programming practice: separate error identification from error handling Suppose m1 is a method that calls another method m2: ● m1 does no try to figure out which errors can possibly come up due to calling m2. ● Instead, m2 passes on error information its caller, m1. Not in notes ● The caller, m1, handles any error information that it is provided with by m2. ● This is why Java has exceptions: exceptions are automatically passed from a method to its callers.
To do for Friday Read “official” slides on exceptions and file I/O ● http://www.cs.mcgill.ca/~cs202/2010- 09/lectures/main/unit-10/10--exceptions.pdf Not in notes ● http://www.cs.mcgill.ca/~cs202/2010- 09/lectures/main/unit-10/10--io.pdf
Recommend
More recommend