API: Check for nosuchsection in all code paths

nosuchsection is currently checked only in the appendtext/prependtext
code path. Add a check for out of range section numbers in the main code
path too.

Bug: 53884
Change-Id: I5bafe8625122ca66415602c37cbca7d7f4c17742
Merge "API: Check for nosuchsection in all code paths"