异常应用场景
Posted macro-renzhansheng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异常应用场景相关的知识,希望对你有一定的参考价值。
Throwable
NoSuchElementException 的异常类典型写法,自定义异常类参考!
public
class NoSuchElementException extends RuntimeException {
private static final long serialVersionUID = 6769829250639411880L;
/**
* Constructs a <code>NoSuchElementException</code> with <tt>null</tt>
* as its error message string.
*/
public NoSuchElementException() {
super();
}
/**
* Constructs a <code>NoSuchElementException</code>, saving a reference
* to the error message string <tt>s</tt> for later retrieval by the
* <tt>getMessage</tt> method.
*
* @param s the detail message.
*/
public NoSuchElementException(String s) {
super(s);
}
}
Throwable cause 异常类构建
public class ConcurrentModificationException extends RuntimeException {
private static final long serialVersionUID = -3666751008965953603L;
/**
* Constructs a ConcurrentModificationException with no
* detail message.
*/
public ConcurrentModificationException() {
}
/**
* Constructs a {@code ConcurrentModificationException} with the
* specified detail message.
*
* @param message the detail message pertaining to this exception.
*/
public ConcurrentModificationException(String message) {
super(message);
}
/**
* Constructs a new exception with the specified cause and a detail
* message of {@code (cause==null ? null : cause.toString())} (which
* typically contains the class and detail message of {@code cause}.
*
* @param cause the cause (which is saved for later retrieval by the
* {@link Throwable#getCause()} method). (A {@code null} value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.7
*/
public ConcurrentModificationException(Throwable cause) {
super(cause);
}
/**
* Constructs a new exception with the specified detail message and
* cause.
*
* <p>Note that the detail message associated with <code>cause</code> is
* <i>not</i> automatically incorporated in this exception‘s detail
* message.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link Throwable#getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link Throwable#getCause()} method). (A {@code null} value
* is permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.7
*/
public ConcurrentModificationException(String message, Throwable cause) {
super(message, cause);
}
}
以上是关于异常应用场景的主要内容,如果未能解决你的问题,请参考以下文章