Skip to content

Files

Latest commit

 

History

History
34 lines (25 loc) · 639 Bytes

prefer_asserts_with_message.md

File metadata and controls

34 lines (25 loc) · 639 Bytes

Pattern: Missing use of assert with message

Issue: -

Description

When assertions fail it's not always simple to understand why. Adding a message to the assert helps the developer to understand why the AssertionError occurs.

Example of incorrect code:

f(a) {
 assert(a != null);
}

class A {
 A(a) : assert(a != null);
}

Example of correct code:

f(a) {
 assert(a != null, 'a must not be null');
}

class A {
 A(a) : assert(a != null, 'a must not be null');
}

Further Reading