AJAX Page - Test and debug

Allowing exception handling

The AJAX Page ASP.NET control has 2 properties helpful for testing and debugging:

- ShowErrorsAtClient: when this property is set to true, an alert box will appear
when an error occurs, with details about the error.
An alert box will also appear for exceptions thrown by the user
(read 'Throwing exceptions for client side at server side' section below).
The default value for this property is true.

- ThrowExceptionsAtClient: when this property is set to true, an exception will be thrown
whenever something goes wrong.
The default value for this property is false.

Throwing exceptions for client side at server side

At server side, users can throw exceptions that will be available on client side.

To do this, use the .NET syntax: throw new Exception("message");

Handling the exceptions client side

The exception handling is different for Synchronous Callback and for Asynchronous Callback.

For Synchronous Callback we can use try catch blocks for error handling:
		
   try{
      alert(ob_post.post(null, "onEvent"));
   }
   catch(ex){
      switch (ex.type){
         // based on the exceptionType do specific instructions
         case ...
      }
   }
	
When an Exception is thrown for Asynchronous Callback, the function that is executed after the callback is done will receive null as the first argument and the Exception name as the second argument.
In the client side function we should first test that if any exceptions occured and continue with the proper code.
		
   function myFunction(result, ex){
      if (ex != null){ // equivalent to if (result == null){
         switch (ex.type){
            // based on the exceptionType do specific instructions
            case ...
         }
      }
      else{
         // if there was no exception
      }
   }
	
Please visit the debugging examples for synchronous and asynchronous callback.

"Works like a charm! Not only did you give an excellent response to our problem, but your suggested solution also gave us a couple of other interesting tips! Thanks a lot!"

Asbjørn Kvalheim
Sense Data

Random testimonial   All testimonials