Friday, December 28, 2012

Published 8:37 AM by with 0 comment

JavaScript Try Catch

Try Catch (Exception)

try
{
}
 catch(err)
{
}
 finally
{
} 
QRCode









Try Catch (Exception)



Javascript Error Handling
Try Catch

Example

try
{
    //lines of codes
}
catch(err)
{
    //err.description
    //err.message
    //err.name
    //err.number
    //err.stack
}
finally
{
    //success or failure , code executes here
}

Throw


Example

function ThrowHelper()
{
    var err = new Error(123,"Error in helper");
    throw err;
}

//elsewhere in code
try
{
    ThrowHelper();
}
catch(ex)
{
    var msg = ex.number +" :"+ex.message;
    //log msg
}

-
    email this       edit

0 comments: