may be used with the finally statement.
try
statement(s)
catch(Exception list)
statement(s)
finally
statement(s)
InputStream in;
int val;
...
try
val = in.read() / in.read();
catch(ArithmeticException e) {
System.out.println("Invalid data. val set to 0.");
val = 0;
}
catch(Exception e)
System.out.println("Exception encountered, but not handled.");
finally {
in.close();
System.out.println("Stream closed.");
}
This is used to perform a loop operation while a certain condition is met.
while (booleanVariable)
statement(s)
while (booleanExpression)
statement(s)
FileInputStream din;
byte info;
while (info = din.read() != -1) // End of File
System.out.println(info);
while (stillValidData) {
info = din.read();
stillValidData = checkData(info); // returns false if data is not valid
}