January 18, 2005

Red code indicates material covered during lecture.

Blue code indicates material to be discussed next time OR assigned as homework.

 

quick quiz

went over Lab1a

              see Deliverable1a.doc 

went over ShortCircuit operator homework -

              see ShortCircuit1.java  

              see ShortCircuit2.java

We will come back to default numeric type next time

continued work on Scanner – see files below

              modified ProductCodes.java – listing 10.2 - page 536

What makes a scanner know that the end of an int has been reached?    It runs into a delimiter

              ReadFromFile1.java

              ReadFromFile1a.java

              ReadFromFile1b.java

              ReadFromFile1c.java

              ReadFromFile1d.java

              ReadFromFileOutputMessages.doc

              ReadFromKeyboard_1.java

              ReadFromKeyboard_1a.java

          ReadFromKeyboardOutputMessages.doc

discussed command line options

              marking screen area

              copying screen area

discussed Exceptions and exception handling  (see below)


Error Categories

              Syntax – at compile time

              Run time

              Logic

 

Exceptions

deal with problems or unusual situations

                                                         /                                         \

                                                   /                                            \

              some can be handled                                         some need exception handlers

              with code      

             

try

{

  // code that may throw Exception goes here

}

catch ( exception_to_catch  variable_name_for_exception )

{

   // what to do as a result of catching this Exception

   // should tell what Exception was caught

}

catch ( exception_to_catch  variable_name_for_exception )

{

   // what to do as a result of catching this Exception

   // should tell what Exception was caught

}

catch ( exception_to_catch  variable_name_for_exception )

{

   // what to do as a result of catching this exception

   // should tell what Exception was caught

}

 

finally

{

   // used in conjunction with try block

   // includes what to do

   //either after exception is caught OR

  //  if it’s not caught

}

 

 

options when Exceptions are thrown

              don’t handle the Exception – program bombs

              handle the Exception where it occurs

              handle the Exception at another point in the program - propagation

 

information provided when exceptions are thrown

              getMessage

              printStackTrace

              see ExceptionScope.java  -  Listing 10.4 – page 540

 

can write your own exceptions

 

 

can explicitly throw an exception.

              see CreatingExceptions.java – Listing 10.5 – page 540

 

checked and unchecked exceptions

checked exceptions

must either be caught by a method OR

must be listed in the throws clause of any method that may throw or propagate it

all exceptions except RunTimeException and its descendants

 

unchecked exceptions

require no throws class

only ones are RunTimeException and its descendants

 

Homework