Try Catch (Exception)
try { } catch(err) { } finally { }
Try Catch (Exception)
Javascript Error Handling
Try CatchExample
try
{
//lines of codes
}
catch(err)
{
//err.description
//err.message
//err.name
//err.number
//err.stack
}
finally
{
//success or failure , code executes here
}
{
//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
}
{
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
}
0 comments:
Post a Comment