Depends whether the error matters. The more it matters, the more you want to prevent it. NullPointerException (NPE) is maybe not the best example, because it is mostly caused by programming errors. You can prevent NPEs arising from objects of the Foo class like this:-
You can use a set method without a defensive copy in this instance because
String is immutable.
I would say, if the possibility of an error matters, do all you can to prevent it happening in the first place. Nice assertive defensive programming, throwing Exceptions where things go wrong.