Error handling

Is there a message box in the javascript? I know I can put response.setMessage(str); to generate a message box but this seems only to work after the function is complete. I want one to create a message intra-code.