I am developing a custom Exception class in which I have the following constructors:
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; } }
And I am creating a new custom exception like this:
private Camera.PreviewCallback SetPreviewCallBack() throws UserException { ....... // Something went wrong throw new UserException("Something failed.", new Throwable(String.valueOf(UserExceptionType.CaptureFailed))); }
But when I insert my throw new UserException(...) , it tells me to surround it with try/catch !! This is not an idea, is it? I want to throw custom exceptions when I need them to be thrown without discarding my new Exceptions with more try/catch clauses.
So what am I doing wrong? What do I misunderstand?
source share