J
Jeff Jarrell
I have a block of code that during development is prone to casting errors.
It is mostly a DataReader type thing.
It looks something like this.
_prtPNID = myDLReader.GetString("prtPNID")
_prtSKU = myDLReader.GetString("prtSKU")
_prtPic = myDLReader.GetString("prtPic")
_prtRsvQty = myDLReader.GetInteger("prtRsvQty")
myDLReader.close
If I don't put it in a try catch block, I can get the right line number as
it bubbles out to try\catch outward. But because I need to put his same
thing into a Transaction, I get an error if I don't get to the
MyDlReader.Close() before the rollback AND the rollback comes before the
Handling of the exception (logging, gui msg, etc). So the original error
gets swallowed up.
So easy enough, put it all into a Try\Catch block and Ensure the reader gets
closed. But as the original exception is rethrown (Throw or Throw ex) the
line number changes to the subsequent Throw line and the "real" line number
is lost.
Try
_prtPNID = myDLReader.GetString("prtPNID")
_prtSKU = myDLReader.GetString("prtSKU")
_prtPic = myDLReader.GetString("prtPic")
_prtRsvQty = myDLReader.GetInteger("prtRsvQty")
catch (ex as exception)
MyDlReader.Close() <--- at this point the ex.StackTrace has the
line number i want
Throw ex <--- the catcher of this gets StackTrace
as being line (aargh)
end try
Ideas?
Thanks,
jeff
It is mostly a DataReader type thing.
It looks something like this.
_prtPNID = myDLReader.GetString("prtPNID")
_prtSKU = myDLReader.GetString("prtSKU")
_prtPic = myDLReader.GetString("prtPic")
_prtRsvQty = myDLReader.GetInteger("prtRsvQty")
myDLReader.close
If I don't put it in a try catch block, I can get the right line number as
it bubbles out to try\catch outward. But because I need to put his same
thing into a Transaction, I get an error if I don't get to the
MyDlReader.Close() before the rollback AND the rollback comes before the
Handling of the exception (logging, gui msg, etc). So the original error
gets swallowed up.
So easy enough, put it all into a Try\Catch block and Ensure the reader gets
closed. But as the original exception is rethrown (Throw or Throw ex) the
line number changes to the subsequent Throw line and the "real" line number
is lost.
Try
_prtPNID = myDLReader.GetString("prtPNID")
_prtSKU = myDLReader.GetString("prtSKU")
_prtPic = myDLReader.GetString("prtPic")
_prtRsvQty = myDLReader.GetInteger("prtRsvQty")
catch (ex as exception)
MyDlReader.Close() <--- at this point the ex.StackTrace has the
line number i want
Throw ex <--- the catcher of this gets StackTrace
as being line (aargh)
end try
Ideas?
Thanks,
jeff