Assume that command is a variable of type String. Write a statement that throws an Exception with a message “null command” if command is null and that throws an Exception with a message “empty command” if command equals the empty string.

LANGUAGE: JAVA

CHALLENGE:

Assume that command is a variable of type String. Write a statement that throws an Exception with a message “null command” if command is null and that throws an Exception with a message “empty command” if command equals the empty string.

SOLUTION:

if (command==null)
throw new Exception("null command");
else if (command.equals(""))
throw new Exception("empty command");