Javascript error throws user into an unformatted notes view

I would like to be able to create a global js routine that will stop js execution on the form. Currently I have created an errorhandler function in the JSHeader → fncHandleError and set window.onerror = fncHandleError. Then when script behind a button on the page encounters an error this routine is fired but the javascript behind the button continues to run and the user is thrown to an unformatted Notes view. Is there a way to stop js execution in the fncHandleError without having to test for the window.onerror value within the various scripts behind all the buttons on the form (which would require alot of retrofitting!)