我正在开发一个自定义异常类,在其中我有以下构造函数:掷自定义异常
public class UserException extends Exception
{
string message;
public UserException() {
super();
}
public UserException(String message, Throwable cause)
{
super(message, cause);
this.cause = cause;
this.message = message;
}
}
我创建一个新的自定义异常这样的:
private Camera.PreviewCallback SetPreviewCallBack() throws UserException {
.......
// Something went wrong
throw new UserException("Something failed.", new Throwable(String.valueOf(UserExceptionType.CaptureFailed)));
}
但是当我插入我的throw new UserException(...)
它告诉我围绕它与try/catch
!这不是主意,不是吗?我想抛出自定义异常,当我需要它们抛出,而不是我的new Exceptions
与更多try/catch
子句。
那么,我在做什么错了?我误解了什么?
你在哪里与此达成? – 2015-04-25 12:23:02