We can catch this exception and therefore prevent the program from terminating. To catch an exception if it arises you include the statements that might throw the exception in a try block. Within the body of the catch clause we can send the Exception object messages, or print it out as here. If the code can throw more than one kind of exception, then you can have several catch clauses with a single try. The most specific ones should be listed first, and the more general ones later.
Exceptions are objects from classes.
Here, more general means a super class, and more specific means a sub class. A null pointer exception is of the latter kind and these need not be caught. In fact, a correct program should never have any of these, so if you have one, you need to fix your program. In the above we need to make John refer to some robot before we send it any messages. The other kind, Exception, is one that can occur even in a correct program.