title: How to know the line number from where the exception is coming from in PHP
body: <p>I am about to finish one project and I noticed that I am getting errors in my error_log file. I have been getting this error when I load my index.php file and in one reload I am getting 21 line lines of the error code. </p>
  
  <p>I have tried debugging from the header.php file. The craziest thing is don't get any error until I load header.php file but when I call header.php in index.php file I get the errors. So I tried to catch the errors by <code>try</code> and <code>catch</code> of from PDO. In the error log file, I am getting error message so I changed my code from this <code>Select Query: ".$e-&gt;getMessage()</code> to <code>Select Query: ".$e-&gt;getFile()</code> and <code>Select Query: ".$e-&gt;getLine()</code>. But, doing this I got line number where the error is getting in not the line it was thrown from.</p>
  
  <p>I think I have a problem in my select query in databse.php. Following is my select query code:</p>
  
  <pre><code>final protected function select($args = array(), $is_die = false){
              try {
  
          $this-&gt;sql = "SELECT ";
          if (isset($args['fields'])) {
              if (is_array($args['fields'])) {
                  $this-&gt;sql .= implode(', ', $args['fields']);
              } else {
                  $this-&gt;sql .= $args['fields'];
              }
          } else {
              $this-&gt;sql .= " * ";
          }
          $this-&gt;sql .= " FROM ";
          if (!isset($this-&gt;table) || empty($this-&gt;table)) {
              throw new Exception("Table not set");
          }
          $this-&gt;sql .= $this-&gt;table;
  
          /*Join Query*/
          if (isset($args['join']) &amp;&amp; !empty($args['join'])) {
              $this-&gt;sql .= " ".$args['join'];
          }
          /*Join Query*/
  
          if (isset($args['where']) &amp;&amp; !empty($args['where'])) {
              if (is_array($args['where'])) {
                  $temp = array();
                  foreach ($args['where'] as $column_name =&gt; $data) {
                      if (!is_array($data)) {
                          $data = array(
                              'value'     =&gt; $data,
                              'operator'  =&gt; '=',
                          );
                      }
                      $str = $column_name.' '.$data['operator'].' :'.str_replace('.', '_', $column_name);
                      $temp[] = $str;
                  }
                  $this-&gt;sql .= " WHERE ".implode(' AND ', $temp);
              } else {
                  $this-&gt;sql .= " WHERE ".$args['where'];
              }
          }
  
          /*Group*/
          if (isset($args['group_by']) &amp;&amp; !empty($args['group_by'])) {
              $this-&gt;sql .= " GROUP BY ".$args['group_by'];
          }
          /*Group*/
  
          /*Order*/
          if (isset($args['order_by']) &amp;&amp; !empty($args['order_by'])) {
              $this-&gt;sql .= " ORDER BY ".$args['order_by'];
          } else {
              $this-&gt;sql .= " ORDER BY ".$this-&gt;table.".id DESC";
          }
          /*Order*/
  
          /*Limit*/
          if (isset($args['limit']) &amp;&amp; !empty($args['limit'])) {
              if (is_array($args['limit'])) {
                  $this-&gt;sql .= " LIMIT ".$args['limit'][0].",".$args['limit'][1];
              } else {
                  $this-&gt;sql .= " LIMIT ".$args['limit'];
              }
          }
          /*Limit*/
          $this-&gt;stmt = $this-&gt;conn-&gt;prepare($this-&gt;sql);
          if (is_array($args['where']) || is_object($args['where'])){
  
              foreach ($args['where'] as $column_name =&gt; $data) {
              $value = is_array($data) ? $data['value'] : $data; //check if passed where statement was an array, fetch value if so
              if (is_int($value)) {
                  $param = PDO::PARAM_INT;
              }elseif (is_bool($value)) {
                  $param = PDO::PARAM_BOOL;
              }elseif (is_null($value)) {
                  $param = PDO::PARAM_NULL;
              }else {
                  $param = PDO::PARAM_STR;
              }
              if ($param) {
                  $this-&gt;stmt-&gt;bindValue(":".str_replace('.', '_', $column_name), $value, $param);
              }
          }
  
          }
  
          if ($is_die) {
              echo $this-&gt;sql;
              debugger($this-&gt;stmt);
              debugger($args, true);
          }
  
          $this-&gt;stmt-&gt;execute();
          $data = $this-&gt;stmt-&gt;fetchAll(PDO::FETCH_OBJ);
          return $data;
          } catch (PDOException $e) {
  
                  error_log(
                      date('Y-m-d h:i:s A').", Select Query: ".$e-&gt;getMessage()."\r\n"
                      , 3, ERROR_PATH.'/error.log');
                  return false;
              } catch (Exception $e) {
                  error_log(
                      date('Y-m-d h:i:s A').", General: ".$e-&gt;getMessage()."\r\n"
                      , 3, ERROR_PATH.'/error.log');
                  return false;
              }
      }
  </code></pre>
  
  <p>Is there a possible way to get the line number of a file where the error is thrown form using try catch or any other?</p>