# angular.scope.$tryEval

Work in Progress This page is currently being revised. It might be incomplete or contain inaccuracies.

## Description

Evaluates the expression in the context of the current scope just like `angular.scope.$eval` with expression parameter, but also wraps it in a try/catch block.

If an exception is thrown then `exceptionHandler` is used to handle the exception.

### Example

             var scope = angular.scope();
             scope.error = function(){ throw 'myerror'; };
             scope.$exceptionHandler = function(e) {this.lastException = e; };

             expect(scope.$eval('error()'));
             expect(scope.lastException).toEqual('myerror');
             this.lastException = null;

             expect(scope.$eval('error()'),  function(e) {this.lastException = e; });
             expect(scope.lastException).toEqual('myerror');

             var body = angular.element(window.document.body);
             expect(scope.$eval('error()'), body);
             expect(body.attr('ng-exception')).toEqual('"myerror"');
             expect(body.hasClass('ng-exception')).toEqual(true);

## Usage

    angular.scope.$tryEval(expression[, exceptionHandler]);

### Parameters

- `expression – {string|function()} –`

  Angular expression to evaluate.

- `exceptionHandler(optional) – {(function()|DOMElement)} –`

  Function to be called or DOMElement to be decorated.

### Returns

`{*}` –

The result of `expression` evaluation.