[SalesForce] do javascript remoting calls need a try/catch

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?

Best Answer

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

Related Topic