我测试了try catch块并尝试在angularjs中使用catch block less方法。但为什么表现彼此不同。请描述一下。
var format = 'yyyy-MM-dd HH:mm:ss Z'
$scope.time1 = new Date();
$scope.time2 = new Date();
$scope.dif = 0;
$scope.TestMethod = function () {
var a = 0;
$scope.time1 = new Date();
for (var i = 0; i < 1000000000; i++) {
a +=i;
}
$scope.time2 = new Date();
calculateDif();
}
$scope.TryCatchMethod = function () {
try {
var a = 0;
$scope.time1 = new Date();
for (var i = 0; i < 1000000000; i++) {
a +=i;
}
$scope.time2 = new Date();
calculateDif();
}
catch (e) {
throw e;
}
}
function calculateDif(){
$scope.dif = $scope.time2-$scope.time1;
}