Skip to main content
added 210 characters in body
Source Link
Paul Bellora
  • 55.4k
  • 18
  • 135
  • 185

Replacing these assertions would take the form of the following validation:

if (rodzic == null) throw new MyValidationException("rodzic cannot be null"); if (rodzic.rodzic == null) throw new MyValidationException("rodzic.rodzic cannot be null"); return rodzic.getBrat(); 

Note that there's a distinction between throwing an Exception and an Error - Exceptions are meant to be caught and handled farther up, while Errors indicate a situation that you can't recover from. For example, you might consider a defining and using a MyValidationError if the failed check is irrecoverable.

Replacing these assertions would take the form of the following validation:

if (rodzic == null) throw new MyValidationException("rodzic cannot be null"); if (rodzic.rodzic == null) throw new MyValidationException("rodzic.rodzic cannot be null"); return rodzic.getBrat(); 

Replacing these assertions would take the form of the following validation:

if (rodzic == null) throw new MyValidationException("rodzic cannot be null"); if (rodzic.rodzic == null) throw new MyValidationException("rodzic.rodzic cannot be null"); return rodzic.getBrat(); 

Note that there's a distinction between throwing an Exception and an Error - Exceptions are meant to be caught and handled farther up, while Errors indicate a situation that you can't recover from. For example, you might consider a defining and using a MyValidationError if the failed check is irrecoverable.

Post Undeleted by Paul Bellora
Post Deleted by Paul Bellora
Source Link
Paul Bellora
  • 55.4k
  • 18
  • 135
  • 185

Replacing these assertions would take the form of the following validation:

if (rodzic == null) throw new MyValidationException("rodzic cannot be null"); if (rodzic.rodzic == null) throw new MyValidationException("rodzic.rodzic cannot be null"); return rodzic.getBrat();