DEV Community

Discussion on: 1 small tip to improve your code readability

Collapse
 
glsolaria profile image
G.L Solaria

If the API code simply does nothing when a user of the API does not satisfy preconditions, how can the API user figure out they are not using it correctly? Wouldn't an exception be more appropriate?

Thread Thread
 
winstonpuckett profile image
Winston Puckett

Totally, but all too often I see things like,
If (acceptable)
{
// Lots of code
}
Else
{
Throw exception
}

Vs what the article talks about of

If (!acceptable)
Throw exception