質問
以下のようなコードがあり、画面にボタンが2つあるのですが、それぞれ押した時の動きが違って困っています。
どちらもexceptionHandlerでexceptionを受けて欲しいんですがどうすればいいですか?
AngularJS: 1.5.6
コード
js
1angular.module("ExceptionApp", []) 2 .controller("TopController", function($scope, ExcService) { 3 $scope.getPosition = function() { 4 var options = { 5 maximumAge: 3000, 6 timeout: 10000, 7 enableHighAccuracy: true 8 }; 9 10 navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options); 11 } 12 13 $scope.exception = function() { 14 exception(); 15 } 16 17 function successCallback(position) {} 18 19 function errorCallback(error) { 20 ExcService.throwException(); 21 } 22 23 function exception() { 24 ExcService.throwException(); 25 } 26 }) 27 .factory('$exceptionHandler', function($log) { 28 return function(exception, cause) { 29 $log.debug("EXCEPTION !!!"); 30 }; 31 }) 32 .service("ExcService", function() { 33 this.throwException = function() { 34 throw new Error(); 35 } 36 });
html
1<div ng-controller="TopController"> 2 <button ng-click="getPosition()">GET POSITION</button> 3 <br><br><br> 4 <button ng-click="exception()">EXCEPTION</button> 5</div>
GET POSITIONボタンを押した時のconsoleの表示
Uncaught Error throwException @ index.js:33 errorCallback @ index.js:19 追記(エラー箇所) function errorCallback(error) { ExcService.throwException(); <= index.js:19 } .service("ExcService", function() { this.throwException = function() { throw new Error(); <= index.js:33 } })
EXCEPTIONボタンを押した時consoleの表示
EXCEPTION !!!
index.jsの33行目、19行目が、どの文に対応するか教えてください。

回答1件
あなたの回答
tips
プレビュー