Goran,
Believe it or not I had tried it both ways. It didn't work.
I guess my out is to just grab the stack trace at that point and parse it. I
know I want it if the particular line contains "LoadRow"). I started to go
down working through the stack frames (unsuccessfully so far) before the
throw, but you know a simple regex on text will take care of it.
Thanks,
jeff
===== this is the stack trace before I throw ============
ex.StackTrace " at System.Data.SqlClient.SqlBuffer.get_Int16()
at System.Data.SqlClient.SqlDataReader.GetInt16(Int32 i)
at whi.pw.core.dal.DLReader.GetShortInteger(String fldName) in
N:\core\core\datalayer\DLReader.cs:line 189
at whi.pw.core.vb.tests.yyyUpdateDemo.RowValues.LoadR ow(DLReader
myDLReader) in N:\core\core.vb.tests\sp_wrappers\yyyUpdateDemo.vb :line 354"
String
======== The part that I am looking for is the "line 354" thing above
==============
==== Here is the stack trace in the caller, after I THROW per your
suggestion =====
StackTrace " at System.Data.SqlClient.SqlBuffer.get_Int16()\r\n
at System.Data.SqlClient.SqlDataReader.GetInt16(Int32 i)\r\n
at whi.pw.core.dal.DLReader.GetShortInteger(String fldName)
in N:\\core\\core\\datalayer\\DLReader.cs:line 189\r\n
at whi.pw.core.vb.tests.yyyUpdateDemo.RowValues.LoadR ow(DLReader
myDLReader)
in N:\\core\\core.vb.tests\\sp_wrappers\\yyyUpdateDem o.vb:line
549\r\n
at whi.pw.core.vb.tests.yyyUpdateDemo.Read()
in N:\\core\\core.vb.tests\\sp_wrappers\\yyyUpdateDem o.vb:line 62\r\n
at whi.pw.core.vb.tests.yyyUpdateDemoTask.Execute(Tas kToken myTaskToken)
in N:\\core\\core.vb.tests\\PipelineTasks\\yyyUpdateD emoTask.vb:line
20\r\n
at whi.pw.core.dal.PipelineBase.Execute(TaskToken myTaskToken) in
N:\\core\\core\\datalayer\\pipeline\\PipelineBase. cs:line 38" string
=== The "line 549" is the THROW line ====== Aargh ====
"Göran Andersson" <gu***@guffa.comwrote in message
news:eJ****************@TK2MSFTNGP02.phx.gbl...
Jeff Jarrell wrote:
>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
Just use:
Throw
>as being line (aargh)
end try
Ideas?
Thanks,
jeff
--
Göran Andersson
_____
http://www.guffa.com