00JavaReviewPart04Slides
00JavaReviewPart04Slides
Programming Review
Exceptions
and
File I/O
• Provides a means to alert and handle Syntax for Creating an Exception
exceptional run-time events public class <<Exception identifier>> extends <<Existing Exception>>
• 3 Elements {
//Constructors
– Creating Exceptions public <<Exception identifier>>()
– Using Exceptions {
– Handling Exceptions super(“<<Exception Message>>”);
}
• Creating Exceptions }
– “Extending” existing Exception
– Only create Constructors that sets the Exception Example
Message public class DivideByZeroException extends Exception
• Using Exceptions {
public DivideByZeroException()
– Method Definition uses “throws” to indicate {
• Using Exceptions {
…
– Method Definition uses “throws” to indicate if(denominator == 0)
to least specific }
catch(DivideByZeroException e)
{
catch(Exception e)
{
e.printStackTrace();
}
• File Input and Output (I/O) allows a program File System Example
to both read and write files to the secondary
storage root
• Files are read left to right THEN top to bottom //Reading and storing to the next integer encountered
– Just like the console you cannot go backwards <<intVar>> = <<fsID>>.nextInt();