Exception handling statements

As a best practice, exception handling should always be included in any JavaScript program. The following code provides an example of using exception handling statements for JavaScript.

function SetFullName(FirstName,LastName) 
{
	if (FirstName != null || LastName != null) 
	{
		FullName=FirstName + “ “ + LastName
		return FullName
	} 
	else 
	{
		throw "InvalidName"
	}
}
try 
{
// statements to try
 var MyName=SetFullName(First, Last) // function could throw exception
}
catch (e) 
{
 MyName="unknown"
 logMyErrors(e) // pass exception object to error handler
}

For detailed information about exception handling, refer to the Statements – Exception Handling Statements section in:

http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide