Let's say I'm writing a custom exception class in Java. What's the difference between the two constructors? In what scenario would I want to use one and the other?
class CustomException extends Exception{
public CustomException(String msg);
public CustomException(String msg, Throwable cause);
or
public CustomException(String msg, Exception ex);
}
Code block this customException once it catch other exceptions that happens in remote call.
} catch(Exception1 | Exception2 | Exception3 ex){
throw new CustomException("custom", ex)
}
Is making Throwable give us a flexibility ? Given the code is only catching exception, is there a difference?