Throwing this exception in place of a simple System.out.println("Invalid datatype "+datatype); will hand over the program flow to either calling method's try/catch block or if no try/catch block, to the JVM.public void processData(byte[] data, int datatype)
{
if(datatype != 1 || datatype != 2)
throw new IllegalArgumentException("Invalid datatype "+datatype);
else System.out.println("Data Processed.");
}
Question: Without knowing if the calling method has the "means" to handle such exception, why would we write a code that could cause JVM to halt a (the) program?
Thanks