Returnerror statement doesn't display message in a .Initialize procedure


I have a .Initialize procedure which contains just this code:

returnerror "Bad move."
message "Hello Jim."

When I open the database, I get no messages. It would appear that the returnerror statement is stopping the procedure but its message is not being displayed. Can somebody please see if they can replicate this?


The returnerror statement stops a procedure and returns to the calling procedure with an error status. The documentation doesn’t say what happens if you use it in a procedure that wasn’t called from another procedure, as it turns out, in that case there is no calling procedure to handle the error, so the running procedure just stops. The .Initialize procedure is not called by another procedure, but you can see this behavior in any procedure that is not called as a subroutine.

I suppose It could be argued that this is a bug, and that returnerror should behave just like the throwerror statement in this situation. But the documentation is silent on this. I’ll have to think about it.

In any case, I think that anything that puts up a modal dialog in an .Initialize procedure is a very bad idea, including just a plain old message statement. What if you open multiple databases and more than one starts throwing up alerts & dialogs? I highly discourage that sort of thing. So even if returnerror worked the way you seem to expect it would, I would discourage using that to display an an alert. If you need to inform the user of something, use the nsnotify statement to display a notification – and don’t turn off notifications!!


I agree - the purpose of this one is to advise the user if he/she opens the primary database (the one that drives the whole system) in the backup volume. I’ve replaced it with an alert and a stop.

I don’t know how you live with notifications - I find them the most irritating feature of macOS.


I would at least recommend using alertsheet in this situation, so that it is only modal to that window.

I don’t know how you live without them, I find them incredibly useful. Before they were available, I used Growl for several years, so I was thrilled when this feature made it into the OS itself. The only time I turn notifications off is if I am recording a screencast.

I find nsnotify very useful for debugging – I can see what is going on without the program stopping and having to click on something. And if needed, I can look at the Notification center to review the debug messages that were generated.


Different strokes.