title: unhandled exception Access violation writing location in Visual Studio
body: <p>Is there a way in Visual Studio 2005 to find out which pointer or variable is causing this access violation? I tried to run in debug mode and break when it happens. By looking at the call stacks, it happens in the end of the function (see below). Could using try/catch be able to find out which pointer it is?</p>
  
  <p><br/></p>
  
  <p><strong>EDIT:</strong>
  Posting my code:</p>
  
  <p>There is a Qt line edit and a checkbox in my application. Toggling the checkbox would switch the data format in the line edit. Like 3'b111 &lt;==> 3'h7. Below is the callback function that is connected to the checkbox stateChanged signal. The exception happens in the end of function, when destructing local variables. </p>
  
  <pre><code>// switch hex/binary format. 15'h0000 &lt;==&gt; 15'b000000000000000
  void switchDataFormat(int checkState) {
      QLineEdit* writeRegLE = this-&gt;getWriteRegLineEdit();
      string oldText = writeRegLE-&gt;text().toStdString();
      string newText = "";
      int maxLength;
      string regLengthText = oldText.substr(0, oldText.find('\''));
      string regValueText = oldText.substr(oldText.find('\'')+2);
      int regLength = this-&gt;getRegLength();
  
      if (checkState == Qt::Unchecked) {
          // switch to binary format
          maxLength = regLengthText.size() + 2 + regLength;
          string binaryText;
          for (int i = 0; i &lt; regValueText.size(); ++i) {
              binaryText += hexToBinary(regValueText[i]);
          }
          newText = regLengthText + "'b" + binaryText.substr(binaryText.size()-regLength);  // trimming leading zeros to fit regLength
      }
      else {
          // switch to hex format
          maxLength = regLengthText.size() + 2 + regLength/4 + 1;
          newText = regLengthText + "'h";
          // zero filling to 4*n bits
          if (regLength%4 != 0) regValueText = string(regLength%4,'0') + regValueText;
          for (int i = 0; i &lt; regValueText.size(); i+=4) {
              newText += binaryToHex(regValueText.substr(i,4));
          }
      }
  
      writeRegLE-&gt;setMaxLength(maxLength);
      writeRegLE-&gt;setText(QString::fromUtf8(newText.c_str()));
  }
  </code></pre>