码迷,mamicode.com
首页 > 其他好文 > 详细

异常应用场景

时间:2020-03-21 13:00:17      阅读:61      评论:0      收藏:0      [点我收藏+]

标签:static   style   tostring   perm   automatic   note   detail   lin   err   

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);
}
}

异常应用场景

标签:static   style   tostring   perm   automatic   note   detail   lin   err   

原文地址:https://www.cnblogs.com/macro-renzhansheng/p/12538157.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!