5

Currently in my javascript remoting calls I check for if (event.status===true) in the callback. I handle any errors in an else. However, it seems it also throws an exception.

Example: [Error] Visualforce Remoting Exception: Unable to connect to the server (communication failure). Object

Is it best practice to wrap JS remoting calls in a try/catch as well? Or do I just let these exceptions display on the console since I'm handling them in the else?

  • Did you ever figure this out? My remoting is also throwing an exception, "Visualforce Remoting Exception: Unable to connect to the server (transaction aborted: timeout)," which I don't seem able to catch inside a try/catch. – tggagne Aug 14 '14 at 20:49
  • Nope, I was really trying to find out what best practice is. Did you try wrapping the whole remoting call inside a try/catch. – Phil B Aug 14 '14 at 20:52
2

The try-catch will create a new varaible in the scope of the current run time, and this will happen every time the catch clause is executed. Now this variable does not exist anywhere else in other parts of the script or even in the same scope.

The variable is created and destroyed at the runtime, this is a unique case in the langauge, so with that being said some browsers may not handle it very nicely and could cause performance issues when the exceptions are caught.

In your case I don't think you will need one because one error won't stop the entire script due to the fact that it is event driven, so if something does go wrong catching the error wouldn't be beneficial

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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