Java-Exception

xiaoxiao2021-03-06  22

1 When you encounter a method M1 (), only THROWS needs to be defined for a specific Exception, and if other methods M2 (), the exception is called, you can use the throw new runtimeException, In this way, M2 () throws out of Exception, the method M3 () of the call M1 () does not want to care about the Exception of M2 THROWS. Such as:

/ ** * Insert Object * @ throws createException * / private void m1 () throws createException {string insertsql = "INTOUSERS (Login, PWD, NICKNAME) VALUES (?,?,?)"; Try {this.m2 );} Catch (DataNotFoundException ex) {throw new runtimeException ("no find max (id) from users" ex);} catch (sqlexception ex) {throw new createException ("User.insert ()" ex);} Finally {conn.close ();}} public void m2 () THROWS DATANOTFOUNDEXCEPTION {.........} PUBLIC VOID M3 () throws createException {m1 ();

2 ================================================= ========================== ClassCastException (when an attempt to add an incompatible object to a class set) InterruptedException (when operating the thread) NOSUCHELEMENTEXCEPTION (NEXT () Returns the next element, if no next element) NullPointerException (if you try to use the Null object to be used, trigger a NullPointerexception Exception) unsupportedOperationException (using certain modifications to an unmodent classset) )

IllegalMonitorStateException Wait () or notify () cannot be found

Specified

Monitor

============================================================================================================================================================================================================= ============================================================================================== This method should not be throwing, otherwise it is to pay attention to the same level or the abnormal subclass: the subclass Override method can not throws an error, and the errors thrown can be the first floor of the father, this layer, the next layer, 4.you cannot USE Error As Well Because It is not like the hierarchy of exception.

转载请注明原文地址:https://www.9cbs.com/read-43132.html

New Post(0)