Two exceptions are thrown. The first is the second Cause, and the first is the second cause.
Only one exception can be thrown. Only one exception can be caught.
Look at the following code. if you think that the execution fails (if the if condition is met) and you cannot execute 2nd throwException (Jeallybean code)
Libcore/luni/src/main/native/libcore_io_Posix.cpp # throwException
146 static void throwGaiException(JNIEnv* env, const char* functionName, int error) { 147 if (errno != 0) { 148 // EAI_SYSTEM should mean "look at errno instead", but both glibc and bionic seem to 149 // mess this up. In particular, if you don't have INTERNET permission, errno will be EACCES 150 // but you'll get EAI_NONAME or EAI_NODATA. So we want our GaiException to have a 151 // potentially-relevant ErrnoException as its cause even if error != EAI_SYSTEM. 152 // http://code.google.com/p/android/issues/detail?id=15722 153 throwErrnoException(env, functionName); 154 // Deliberately fall through to throw another exception... 155 } 156 static jmethodID ctor3 = env->GetMethodID(JniConstants::gaiExceptionClass, 157 "<init>", "(Ljava/lang/String;ILjava/lang/Throwable;)V"); 158 static jmethodID ctor2 = env->GetMethodID(JniConstants::gaiExceptionClass, 159 "<init>", "(Ljava/lang/String;I)V"); 160 throwException(env, JniConstants::gaiExceptionClass, ctor3, ctor2, functionName, error); 161 }
This is not an exception of native C ++, but an exception that native sends to the java layer.
Let's look at the following function. If the Pending Exception (env-> ExceptionOccurred) occurs, the Pending Exception will become the cause of the current Exception.
113 static void throwException(JNIEnv* env, jclass exceptionClass, jmethodID ctor3, jmethodID ctor2, 114 const char* functionName, int error) { 115 jthrowable cause = NULL; 116 if (env->ExceptionCheck()) { 117 cause = env->ExceptionOccurred(); 118 env->ExceptionClear(); 119 } 120 121 ScopedLocalRef<jstring> detailMessage(env, env->NewStringUTF(functionName)); 122 if (detailMessage.get() == NULL) { 123 // Not really much we can do here. We're probably dead in the water, 124 // but let's try to stumble on... 125 env->ExceptionClear(); 126 } 127 128 jobject exception; 129 if (cause != NULL) { 130 exception = env->NewObject(exceptionClass, ctor3, detailMessage.get(), error, cause); 131 } else { 132 exception = env->NewObject(exceptionClass, ctor2, detailMessage.get(), error); 133 } 134 env->Throw(reinterpret_cast<jthrowable>(exception)); 135 }
Let's look at the following:
Libcore/luni/src/main/java/net/InetAddress. java # getAllByNameImpl
417 } catch (GaiException gaiException) { 418 // If the failure appears to have been a lack of INTERNET permission, throw a clear 419 // SecurityException to aid in debugging this common mistake. 420 // http://code.google.com/p/android/issues/detail?id=15722 421 if (gaiException.getCause() instanceof ErrnoException) { 422 if (((ErrnoException) gaiException.getCause()).errno == EACCES) { 423 throw new SecurityException("Permission denied (missing INTERNET permission?)", gaiException); 424 } 425 } 426 // Otherwise, throw an UnknownHostException. 427 String detailMessage = "Unable to resolve host \"" + host + "\": " + Libcore.os.gai_strerror(gaiException.error); 428 addressCache.putUnknownHost(host, detailMessage); 429 throw gaiException.rethrowAsUnknownHostException(detailMessage); 430 }
When GaiException is detected, check whether the Cause is ErrnoException.
Java experiment: write a program, input two numbers on the keyboard, divide the first number by the second number, and display the result. Handle all possible exceptions.
Import java. awt .*;
Import javax. swing .*;
Import java. awt. event .*;
Public class FuctJFrame extends JFrame implements ActionListener {
/**
*
*/
Private static final long serialVersionUID = 1L;
JLabel jlabel = new JLabel ("enter two numbers :");
JLabel jlabel1 = new JLabel ();
JTextField jtextfield = new JTextField ();
JButton jbutton = new JButton ("= ");
JTextField jtextfield1 = new JTextField ();
Public FuctJFrame (){
SetSize (300,300 );
SetTitle ("division of two numbers ");
SetLocation (251,251 );
GetContentPane (). setLayout (null );
Jlabel. setBounds (new Rectangle (, 50 ));
Jtextfield. setBounds (new Rectangle (, 80 ));
Jtextfield1.setBounds (new Rectangle (100,110,100, 20 ));
Jbutton. setBounds (new Rectangle (115,140 ));
Jlabel1.setBounds (new Rectangle (120,200,100, 20 ));
Jlabel1.setForeground (Color. RED );
Jbutton. addActionListener (this );
GetContentPane (). add (jlabel );
GetContentPane (). add (jtextfield );
GetContentPane (). add (jbutton );
GetContentPane (). add (jtextfield1 );
GetContentPane (). add (jlabel1 );
}
Public void actionreceivmed (ActionEvent e ){
Try {
Double sum;
Sum = Double. parseDouble (jtextfield. getText ()/Double. parseDouble (jtextfield1.getText ());
Jlabel1.setText ("" + sum );
If (Double. parseDouble (jtextfield1.getText () = 0.0)
Jlabel1.setText ("the divisor cannot be 0 ");
} Catch (Exception ex ){
JOptionPane. showMessageDialog (this, "enter a number ");
}
}
Public static void main (String [] arqs ){
FuctJFrame x = new FuctJFra... the remaining full text>
The first child has an abnormal expression of "L". The second child can do the same.
Possible
Phenylketonurics, this results in the accumulation of tryptophan and Its ketone acid, which are discharged from the urine. Clinical manifestations include low intelligence, convulsions, and reduced pigmentation. This disease is an autorecessive inheritance. The incidence rate varies with race. About 1/14000 in the United States, 1/60000 in Japan, and 1/16500 in China.