Allowing exception handling
The AJAXPage 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.
| | |
| "Thank you for your immediate solutions. As a programmer I am inspired by your work attitude and solutions. You have done a great job for me." |
Suresh Kumar |
|
| | |
|