title: protractor - try catch - error handling
body: <p>I am looking for an element and if the element is not present, I want to give a decent error message saying "element not present"; but it comes out of the block and throwing a message like element not found for the <code>xpath</code>.</p>
  
  <p>Below is the code I have tried but I'm still getting the same error. 
  For example a=protractor and  if the value is present, it says text prevails - protractor; and in case it is not there, instead of saying element not present/error occurs it says "no element found <code>element(by.xpath("//div[@title='"protractor"']"))</code> followed by a big error message. 
  How to resolve this?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>this.gridverify = function (a) {
          browser.sleep(10000);
          try {             
              var elm = element(by.xpath("//div[@title='" + a + "']"));
              if (elm.isPresent) {
                  elm.getText().then(function (x) {
                      console.log("text Prevails: " + x);
                  })
              }
              else {                   
                  console.log('element not present');
              }
          }
          catch (err) {
              console.log('error occured');
          }
      }</code></pre>
  </div>
  </div>
  </p>