In the script, turn on error capture.
Then have a line that reads something like;
If get(lasterror) = 401
show custome dialogue "blah blah blah"
or you can set it to go to original layout, or whatever you want.
That way, if the error occurs, it will do what you tell it to instead of bringing up that error message you mentioned.
The 401 may not be the correct error code, but if you just search in the help, it will bring up a list of error codes, just find the appropriate one.
You need to capture first if there are related records. You can do this by using Set Error Capture [On] in conjunction with Get ( LastError ) or if checking for related records from A parent record you can use something like.
If [ not IsEmpty ( child::pkChildID ) ] or just - child::pkChildID coudl be used in this case.
Go to Related Records
It checks to see if the first related record's primary key is there. If there are no child records then obviously it wouldnt be there.