Unusual chain

xiaoxiao2021-03-06  95

When we throw an exception, this exception needs to include information with other exceptions, we can use Java's exception chain mechanism. Because Excepiton, RuntimeException, and Throwable can achieve link other exception information by constructor parameters such as:

Throw new runtimeException (e);

If it is not the three exceptions above, then you need to implement it with the initcause () method, such as:

DynamicfieldSexception DFE =

NEW DYNAMICFIELDSEXCEPTION ();

DFE.INITCAUSE

New nullpointerserexception ());

Throw DFE;

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

New Post(0)