Hi @sara,
You can use the try-catch blocks in code behind and alert the error message returned or you can customize an error message based on the exception returned.
Here is an example of how to make Javascript calls from code behind:
Regards, Eddy.