Understanding a 'thread was being aborted/mscorlib' exception

D

darrel

I have a function that calls a class that writes a dataset that I've passed
to it out as an excel spreadheet and returns it to the browser:

my function
try
makeExcelFile(mydataset)
catch
response write the exceptions
end try
end function

This works. However, at the very bottom of my excel spreadsheet that gets
generated, it prints out the CATCH response write from my function:

Thread was being aborted.
mscorlib

From a bit of googling, I can't quite tell if that's an error, or just a
normal response and that I probably should just check for that specific
response and not bother writing it out.

I'm also a bit confused as to why it's writing the error the spreadsheet.
Should the spreadsheet be written, that function returns the exception, then
my function catch it and, in turn, write the exception back to the screen?

-Darrel
 
D

darrel

Oh, and here's the function that is apparently returning that exception:

Public Shared Sub Convert(ByVal ds As DataSet, ByVal response As
HttpResponse)
'first let's clean up the response.object
response.Clear()
response.Charset = ""
'set the response mime type for excel
response.ContentType = "application/vnd.ms-excel"
'create a string writer
Dim stringWrite As New System.IO.StringWriter
'create an htmltextwriter which uses the stringwriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
'instantiate a datagrid
Dim dg As New DataGrid
'set the datagrid datasource to the dataset passed in
dg.DataSource = ds.Tables(0)
'bind the datagrid
dg.DataBind()
'tell the datagrid to render itself to our htmltextwriter
dg.RenderControl(htmlWrite)
'all that's left is to output the html
response.Write(stringWrite.ToString)
response.End()
End Sub

-darrel
 
D

darrel

From the blog of a friend:
"This problem occurs when calling a Response.Redirect() or a
Server.Transfer() within a Try...Catch block. This is because the
Response.Redirect() method will call the Response.End() method and the
Response.End() method will call the Abort() method of the running thread."

Thanks. I saw that too. However, neither of the functions are calling a
server transfer or response.redirect. It IS using a bunch of other
response.* calls, though (see my other reply) so perhaps one of those is the
culprit.

AFAICT, there's no actual error, as all the data is rendered.

-Darrel
 
S

Steven Spits

darrel said:
This works. However, at the very bottom of my excel spreadsheet that gets
generated, it prints out the CATCH response write from my function:

Thread was being aborted.
mscorlib

From the blog of a friend:

"This problem occurs when calling a Response.Redirect() or a
Server.Transfer() within a Try...Catch block. This is because the
Response.Redirect() method will call the Response.End() method and the
Response.End() method will call the Abort() method of the running thread."

Steven

- - -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top