Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I ran into a issue when using apex:actionSupport that was swallowing JavaScript errors.

Snippet from page:

<apex:inputField value="{!controllerOli.CustomFieldStartDate__c}" id="start_date" required="true" >
    <apex:actionSupport event="onchange"                                                
<apex:actionStatus startText="applying value..." id="statusStart"/>

// The rendered property will only render this outputpanel via ajax. Not on initial page load
<apex:outputPanel id="fooOutputPanel" rendered="{! someControllerProperty }">

        // Note: the ready function will never occur with ajax rendering
        //$j(document).ready(function() {
        //    console.log('jquery ready');
        //    setupValidation();

        function setupValidation() {
            console.log('DEBUG - Validating.');
            // This example exception won't appear in the Chrome JavaScript console
            // Runtime exceptions, i.e. method doesn't exist, are also swallowed.
            throw 'bang';
            console.log('DEBUG - Unreachable.');


I'd expect to see some indication of the JavaScript exception in the Chrome Console. Instead the oncomplete JavaScript method is called, the first log message is recorded, and then nothing.

Chrome JavaScript Console not showing expected exception

Right now I've reverted to wrapping my custom JavaScript in a try/catch and writing the exception to the console.

Is there a better way to handle exceptions with an apex:actionSupport?

I manually called the same JavaScript method via the console and was able to see the exception.

Chrome JavaScript Console not showing expected exception. Manual call to same method shows the exception

share|improve this question
Rather than throwing an exception, have you tried introducing a runtime exception such as invoking a non existent method or such? – techtrekker Nov 29 '12 at 0:45
@techtrekker, this question originated from a runtime exception that occured due to a non existent method that was defined in a jQuery plugin. For some reason in one clients org the plugin methods didn't exist. I suspect there were conflicts with other packages and/or custom code. It did take me some time to track down the bug due to disappearing exceptions. – Daniel Ballinger Nov 29 '12 at 0:55
Seems to me that since setupValidation() is called on dom ready in an outputPanel that is always rendered, that the error (or lack thereof) you've taken a screenshot of doesn't necessarily have anything to do with the actionSupport. Does the same problem occur if you comment out everything besides "fooOutputPanel"? – Phil Rymek Nov 29 '12 at 4:28
@PhilR I'm fairly certain it is the actionSupport. The outputPanel in the example was conditionally rendered, but I had initially excluded this from the example code. I've added another screenshot. The first console log message occurs via the actionSupport call to the onComplete method. If I then manually call the same method I see the uncaught exception in the console. – Daniel Ballinger Nov 29 '12 at 20:20

This isn't much better than your logging solution from an end users point of view, but if for some reason you absolutely need to have a JavaScript Error generated you could wrap your callback in a setTimeout.

<apex:actionSupport event="onchange"                                                

Behind the scenes the oncomplete callback will only schedule the setupValidation() for future execution and then it will complete. Because the future execution will be outside of the swallowing parent context that you observed, the Error will not get swallowed. However, the stacktrace will not preserved either, although I'm not sure how useful that would be anyway. In chrome you'll get:

Uncaught Error: bang
(anonymous function)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.