( 1 ) Read the following code ( Catchwho.java ), write out the program run result:
( 2 ) Write Catchwho2.java Results of program Operation
( 3 ) Please read first Embedfinally.java example, run it again, observe its output, and summarize it.
Summary: when there are multiple layers of nested Finally, exceptions are thrown at different levels and thrown at different locations, which can result in a different order of finally statement block execution.
( 4 according to the analysis of several examples of the program, please self-summarize Java the basic flow of multi-layered nested exception handling.
When the try-catch-finally are nested with each other, the try-catch-finally of the inner layer is processed first. When the try throws an exception that matches the catch, the code executes in the corresponding catch (). If the catch also has an exception, the program detects if there is an exception in finally and overwrites if there is one. If there is only try-finally, then finally is executed, and if finally there is no exception, the exception in the handle try is returned, and if finally there is an exception, the exception in the try is overwritten
( 5 ) Hands -on brain
import javax.swing.*;
Public class Score {
Public Static void Main (String []args) {
int n=0;
Try {
String Str=joptionpane. Showinputdialog ("Please enter student score:");
N=integer. parseint (str);
if (0<=n&&n<60)
{
Joptionpane. Showmessagedialog (null, "failed",
"Student Performance", Javax.swing.JOptionPane. information_message);
}
if (n>=60&&n<70)
{Joptionpane. Showmessagedialog (null, "pass",
"Student Performance", Javax.swing.JOptionPane. information_message);}
if (n>=70&&n<80)
{
Joptionpane. Showmessagedialog (null, "medium",
"Student Performance", Javax.swing.JOptionPane. information_message);
}
if (n>=80&&n<90)
{
Joptionpane. Showmessagedialog (null, "good",
"Student Performance", Javax.swing.JOptionPane. information_message);
}
if (n>=90&&n<=100)
{
Joptionpane. Showmessagedialog (null, "excellent",
"Student Performance", Javax.swing.JOptionPane. information_message);
}
if (n>100)
{
Joptionpane. Showmessagedialog (null, "incorrect input",
"Student Performance", Javax.swing.JOptionPane. information_message);
}
if (n<0)
{
Joptionpane. Showmessagedialog (null, "incorrect input",
"Student Performance", Javax.swing.JOptionPane. information_message);
}}
Catch (Exception e)
{Joptionpane. Showmessagedialog (null, "incorrect input",
"Student Performance", Javax.swing.JOptionPane. information_message);
}}}
Operation Result:
Java Job 7