By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,602 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,602 IT Pros & Developers. It's quick & easy.

Use Server.Transfer in a try-catch

P: n/a
Hello
I'm trying to use a Server.Transfer in a try-catch (I cannot put it outside the Try-Catch as it is nested deep within a component that is called in a try-catch loop)

The problem is that the Server.Transfer always throws the ThreadAbortException. MSDN acknowledges that this is a unque exception that will be automatically rethrown - i.e. it can't be swallowed. Does anyone know if there is extar code I can write (maybe something in the threading namespace) that effectively swallows this so it doesn't rethrow

For example

Tr
Tr
Server.Transfer("ServB.aspx"
Catch ex As System.Threading.ThreadAbortExceptio
'want to kill thread so it doesn't rethrow to "Second Exception handler
Catch ex As Exceptio
Throw e
End Tr
Catch ex As Exceptio
'Second Exception handle
strEx = ex.Messag
End Tr

Thanks
Mark
Nov 18 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Hi, Mark

did you try to use simple return; ?

Does this prevent further exceptions?

Alex

"Mark" <an*******@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
Hello,
I'm trying to use a Server.Transfer in a try-catch (I cannot put it outside the Try-Catch as it is nested deep within a component that is called
in a try-catch loop).
The problem is that the Server.Transfer always throws the ThreadAbortException. MSDN acknowledges that this is a unque exception that
will be automatically rethrown - i.e. it can't be swallowed. Does anyone
know if there is extar code I can write (maybe something in the threading
namespace) that effectively swallows this so it doesn't rethrow?
For example:

Try
Try
Server.Transfer("ServB.aspx")
Catch ex As System.Threading.ThreadAbortException
'want to kill thread so it doesn't rethrow to "Second Exception handler" Catch ex As Exception
Throw ex
End Try
Catch ex As Exception
'Second Exception handler
strEx = ex.Message
End Try

Thanks,
Mark

Nov 18 '05 #2

P: n/a
Hey Alex
Nice suggestion, I tried it and it doesn't work - the exception is still thrown

Mar

----- AlexS wrote: ----

Hi, Mar

did you try to use simple return;

Does this prevent further exceptions

Ale

"Mark" <an*******@discussions.microsoft.com> wrote in messag
news:D6**********************************@microsof t.com..
Hello
I'm trying to use a Server.Transfer in a try-catch (I cannot put i outside the Try-Catch as it is nested deep within a component that is calle
in a try-catch loop)
The problem is that the Server.Transfer always throws th ThreadAbortException. MSDN acknowledges that this is a unque exception tha
will be automatically rethrown - i.e. it can't be swallowed. Does anyon
know if there is extar code I can write (maybe something in the threadin
namespace) that effectively swallows this so it doesn't rethrow For example
Tr

Tr
Server.Transfer("ServB.aspx"
Catch ex As System.Threading.ThreadAbortExceptio
'want to kill thread so it doesn't rethrow to "Secon

Exception handler Catch ex As Exceptio
Throw e
End Tr
Catch ex As Exceptio
'Second Exception handle
strEx = ex.Messag
End Tr
Thanks

Mar


Nov 18 '05 #3

P: n/a
Calling Server.Transfer is like calling Exit from an exe. It means you
are all done, and processing of this request should end. If you still
have more code that you want to execute after calling Server.Transfer,
then you need to reorganize your code so that executes first, by, for
example, returning a status code from "deep within" your component, that
tells the calling code to execute the transfer.

-Jason

Mark wrote:
Hey Alex,
Nice suggestion, I tried it and it doesn't work - the exception is still thrown.

Mark

----- AlexS wrote: -----

Hi, Mark

did you try to use simple return; ?

Does this prevent further exceptions?

Alex

"Mark" <an*******@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
> Hello,
> I'm trying to use a Server.Transfer in a try-catch (I cannot put it

outside the Try-Catch as it is nested deep within a component that is called
in a try-catch loop).
>> The problem is that the Server.Transfer always throws the ThreadAbortException. MSDN acknowledges that this is a unque exception that
will be automatically rethrown - i.e. it can't be swallowed. Does anyone
know if there is extar code I can write (maybe something in the threading
namespace) that effectively swallows this so it doesn't rethrow? >> For example:
>> Try

> Try
> Server.Transfer("ServB.aspx")
> Catch ex As System.Threading.ThreadAbortException
> 'want to kill thread so it doesn't rethrow to "Second

Exception handler"
> Catch ex As Exception
> Throw ex
> End Try
> Catch ex As Exception
> 'Second Exception handler
> strEx = ex.Message
> End Try
>> Thanks,

> Mark


Nov 18 '05 #4

P: n/a
Try Server.Execute. I don't know if it will help in your exact application
but it may be worth a try.

Dale

"Jason DeFontes" <ja***@defontes.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
Calling Server.Transfer is like calling Exit from an exe. It means you
are all done, and processing of this request should end. If you still
have more code that you want to execute after calling Server.Transfer,
then you need to reorganize your code so that executes first, by, for
example, returning a status code from "deep within" your component, that
tells the calling code to execute the transfer.

-Jason

Mark wrote:
Hey Alex,
Nice suggestion, I tried it and it doesn't work - the exception is still thrown.
Mark

----- AlexS wrote: -----

Hi, Mark

did you try to use simple return; ?

Does this prevent further exceptions?

Alex

"Mark" <an*******@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
> Hello,
> I'm trying to use a Server.Transfer in a try-catch (I cannot
put it outside the Try-Catch as it is nested deep within a component that is called in a try-catch loop).
>> The problem is that the Server.Transfer always throws the

ThreadAbortException. MSDN acknowledges that this is a unque exception that will be automatically rethrown - i.e. it can't be swallowed. Does anyone know if there is extar code I can write (maybe something in the threading namespace) that effectively swallows this so it doesn't rethrow?
>> For example:
>> Try
> Try
> Server.Transfer("ServB.aspx")
> Catch ex As System.Threading.ThreadAbortException
> 'want to kill thread so it doesn't rethrow to
"Second Exception handler"
> Catch ex As Exception
> Throw ex
> End Try
> Catch ex As Exception
> 'Second Exception handler
> strEx = ex.Message
> End Try
>> Thanks,
> Mark


Nov 18 '05 #5

P: n/a
Hey Jason
I thought that Server.Transfer was like a goto, you transfer (goto) from Page A to Page B
I'm not trying to run any code after the server.transfer on page A, rather I'm trying to stop running all Page A code (in this case the try-catch block) and transfer to page B. The problem is that it keeps bubbling up the ThreadAbortException

Any ideas

Thanks
Mar
----- Jason DeFontes wrote: ----

Calling Server.Transfer is like calling Exit from an exe. It means you
are all done, and processing of this request should end. If you still
have more code that you want to execute after calling Server.Transfer,
then you need to reorganize your code so that executes first, by, for
example, returning a status code from "deep within" your component, that
tells the calling code to execute the transfer

-Jaso

Mark wrote
Hey Alex
Nice suggestion, I tried it and it doesn't work - the exception is still thrown
Mar
----- AlexS wrote: ----
Hi, Mar
did you try to use simple return;
Does this prevent further exceptions
Ale
"Mark" <an*******@discussions.microsoft.com> wrote in messag

news:D6**********************************@microsof t.com..
Hello
I'm trying to use a Server.Transfer in a try-catch (I cannot put i

outside the Try-Catch as it is nested deep within a component that is calle
in a try-catch loop)
The problem is that the Server.Transfer always throws th ThreadAbortException. MSDN acknowledges that this is a unque exception tha
will be automatically rethrown - i.e. it can't be swallowed. Does anyon
know if there is extar code I can write (maybe something in the threadin
namespace) that effectively swallows this so it doesn't rethrow For example
Tr

Tr
Server.Transfer("ServB.aspx"
Catch ex As System.Threading.ThreadAbortExceptio
'want to kill thread so it doesn't rethrow to "Secon

Exception handler
Catch ex As Exceptio
Throw e
End Tr
Catch ex As Exceptio
'Second Exception handle
strEx = ex.Messag
End Tr
Thanks

Mar

Nov 18 '05 #6

P: n/a
This is why Server.Transfer throws the exception in the first place, to
unwind the stack so nothing else gets executed. Just leave it alone and
let it do it's thing.

-Jason

Mark wrote:
Hey Jason,
I thought that Server.Transfer was like a goto, you transfer (goto) from Page A to Page B.
I'm not trying to run any code after the server.transfer on page A, rather I'm trying to stop running all Page A code (in this case the try-catch block) and transfer to page B. The problem is that it keeps bubbling up the ThreadAbortException.

Any ideas?

Thanks,
Mark
----- Jason DeFontes wrote: -----

Calling Server.Transfer is like calling Exit from an exe. It means you
are all done, and processing of this request should end. If you still
have more code that you want to execute after calling Server.Transfer,
then you need to reorganize your code so that executes first, by, for
example, returning a status code from "deep within" your component, that
tells the calling code to execute the transfer.

-Jason

Mark wrote:
> Hey Alex,
> Nice suggestion, I tried it and it doesn't work - the exception is still thrown.
>> Mark
>> ----- AlexS wrote: -----
>> Hi, Mark
>> did you try to use simple return; ?
>> Does this prevent further exceptions?
>> Alex
>> "Mark" <an*******@discussions.microsoft.com> wrote in message

> news:D6**********************************@microsof t.com...
>> Hello,
>> I'm trying to use a Server.Transfer in a try-catch (I cannot put it

> outside the Try-Catch as it is nested deep within a component that is called
> in a try-catch loop).
>>> The problem is that the Server.Transfer always throws the

> ThreadAbortException. MSDN acknowledges that this is a unque exception that
> will be automatically rethrown - i.e. it can't be swallowed. Does anyone
> know if there is extar code I can write (maybe something in the threading
> namespace) that effectively swallows this so it doesn't rethrow?
>>> For example:
>>> Try
>> Try
>> Server.Transfer("ServB.aspx")
>> Catch ex As System.Threading.ThreadAbortException
>> 'want to kill thread so it doesn't rethrow to "Second

> Exception handler"
>> Catch ex As Exception
>> Throw ex
>> End Try
>> Catch ex As Exception
>> 'Second Exception handler
>> strEx = ex.Message
>> End Try
>>> Thanks,
>> Mark
>>>

Nov 18 '05 #7

P: n/a
The problem is if I just "leave it alone", the exception it throws will be published (global error handler to catch all exceptions and publish them). I am stuck with someone else's architecture that requires me to switch pages with a component that uses Server.Transfer, and therefore an exception will be logged at every new page - which is what I want to avoid

That's why I'm trying to find a way to swallow the ThreadAbortException

Thanks
Mar

----- Jason DeFontes wrote: ----

This is why Server.Transfer throws the exception in the first place, to
unwind the stack so nothing else gets executed. Just leave it alone and
let it do it's thing

-Jaso

Mark wrote
Hey Jason
I thought that Server.Transfer was like a goto, you transfer (goto) from Page A to Page B
I'm not trying to run any code after the server.transfer on page A, rather I'm trying to stop running all Page A code (in this case the try-catch block) and transfer to page B. The problem is that it keeps bubbling up the ThreadAbortException
Any ideas
Thanks

Mar
----- Jason DeFontes wrote: ----

Calling Server.Transfer is like calling Exit from an exe. It means you

are all done, and processing of this request should end. If you still
have more code that you want to execute after calling Server.Transfer,
then you need to reorganize your code so that executes first, by, for
example, returning a status code from "deep within" your component, that
tells the calling code to execute the transfer
-Jaso
Mark wrote
Hey Alex

Nice suggestion, I tried it and it doesn't work - the exception is still thrown
Mar
----- AlexS wrote: ----
Hi, Mar
did you try to use simple return;
Does this prevent further exceptions
Ale
"Mark" <an*******@discussions.microsoft.com> wrote in messag

news:D6**********************************@microsof t.com..
Hello
I'm trying to use a Server.Transfer in a try-catch (I cannot put i

outside the Try-Catch as it is nested deep within a component that is calle
in a try-catch loop)
The problem is that the Server.Transfer always throws th

ThreadAbortException. MSDN acknowledges that this is a unque exception tha
will be automatically rethrown - i.e. it can't be swallowed. Does anyon
know if there is extar code I can write (maybe something in the threadin
namespace) that effectively swallows this so it doesn't rethrow
For example
Tr
Tr
Server.Transfer("ServB.aspx"
Catch ex As System.Threading.ThreadAbortExceptio
'want to kill thread so it doesn't rethrow to "Secon

Exception handler
Catch ex As Exceptio
Throw e
End Tr
Catch ex As Exceptio
'Second Exception handle
strEx = ex.Messag
End Tr
Thanks
Mar

Nov 18 '05 #8

P: n/a
I think your only option is to ignore the ThreadAbortException in your
logging. Possibly you can inspect the stack trace of the exception and
only ignore it if Server.Transfer is in the stack.

-Jason

Mark wrote:
The problem is if I just "leave it alone", the exception it throws will be published (global error handler to catch all exceptions and publish them). I am stuck with someone else's architecture that requires me to switch pages with a component that uses Server.Transfer, and therefore an exception will be logged at every new page - which is what I want to avoid.

That's why I'm trying to find a way to swallow the ThreadAbortException.

Thanks,
Mark

----- Jason DeFontes wrote: -----

This is why Server.Transfer throws the exception in the first place, to
unwind the stack so nothing else gets executed. Just leave it alone and
let it do it's thing.

-Jason

Mark wrote:
> Hey Jason,
> I thought that Server.Transfer was like a goto, you transfer (goto) from Page A to Page B.
> I'm not trying to run any code after the server.transfer on page A, rather I'm trying to stop running all Page A code (in this case the try-catch block) and transfer to page B. The problem is that it keeps bubbling up the ThreadAbortException.
>> Any ideas?
>> Thanks,

> Mark
>>> ----- Jason DeFontes wrote: -----
>> Calling Server.Transfer is like calling Exit from an exe. It means you

> are all done, and processing of this request should end. If you still
> have more code that you want to execute after calling Server.Transfer,
> then you need to reorganize your code so that executes first, by, for
> example, returning a status code from "deep within" your component, that
> tells the calling code to execute the transfer.
>> -Jason
>> Mark wrote:
>>> Hey Alex,
>> Nice suggestion, I tried it and it doesn't work - the exception is still thrown.
>>> Mark
>>> ----- AlexS wrote: -----
>>> Hi, Mark
>>> did you try to use simple return; ?
>>> Does this prevent further exceptions?
>>> Alex
>>> "Mark" <an*******@discussions.microsoft.com> wrote in message
>> news:D6**********************************@microsof t.com...
>>> Hello,
>>> I'm trying to use a Server.Transfer in a try-catch (I cannot put it
>> outside the Try-Catch as it is nested deep within a component that is called
>> in a try-catch loop).
>>>> The problem is that the Server.Transfer always throws the
>> ThreadAbortException. MSDN acknowledges that this is a unque exception that
>> will be automatically rethrown - i.e. it can't be swallowed. Does anyone
>> know if there is extar code I can write (maybe something in the threading
>> namespace) that effectively swallows this so it doesn't rethrow?
>>>> For example:
>>>> Try
>>> Try
>>> Server.Transfer("ServB.aspx")
>>> Catch ex As System.Threading.ThreadAbortException
>>> 'want to kill thread so it doesn't rethrow to "Second
>> Exception handler"
>>> Catch ex As Exception
>>> Throw ex
>>> End Try
>>> Catch ex As Exception
>>> 'Second Exception handler
>>> strEx = ex.Message
>>> End Try
>>>> Thanks,
>>> Mark
>>>>

Nov 18 '05 #9

P: n/a
Server.Execute is like a goto. It runs the code in the new page and returns
to the original page. In fact, you'll even end up with two sets of header
HTML tags in the client source.

Server.Transfer is more like changing processes.

Dale

"Mark" <an*******@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
Hey Jason,
I thought that Server.Transfer was like a goto, you transfer (goto) from Page A to Page B. I'm not trying to run any code after the server.transfer on page A, rather I'm trying to stop running all Page A code (in this case the try-catch
block) and transfer to page B. The problem is that it keeps bubbling up the
ThreadAbortException.
Any ideas?

Thanks,
Mark
----- Jason DeFontes wrote: -----

Calling Server.Transfer is like calling Exit from an exe. It means you are all done, and processing of this request should end. If you still
have more code that you want to execute after calling Server.Transfer, then you need to reorganize your code so that executes first, by, for
example, returning a status code from "deep within" your component, that tells the calling code to execute the transfer.

-Jason

Mark wrote:
> Hey Alex,
> Nice suggestion, I tried it and it doesn't work - the exception is still thrown.
>> Mark
>> ----- AlexS wrote: -----
>> Hi, Mark
>> did you try to use simple return; ?
>> Does this prevent further exceptions?
>> Alex
>> "Mark" <an*******@discussions.microsoft.com> wrote in message

> news:D6**********************************@microsof t.com...
>> Hello,
>> I'm trying to use a Server.Transfer in a try-catch (I cannot put it
> outside the Try-Catch as it is nested deep within a component that is called > in a try-catch loop).
>>> The problem is that the Server.Transfer always throws the

> ThreadAbortException. MSDN acknowledges that this is a unque exception that > will be automatically rethrown - i.e. it can't be swallowed. Does anyone > know if there is extar code I can write (maybe something in the threading > namespace) that effectively swallows this so it doesn't rethrow? >>> For example:
>>> Try
>> Try
>> Server.Transfer("ServB.aspx")
>> Catch ex As System.Threading.ThreadAbortException
>> 'want to kill thread so it doesn't rethrow to

"Second > Exception handler"
>> Catch ex As Exception
>> Throw ex
>> End Try
>> Catch ex As Exception
>> 'Second Exception handler
>> strEx = ex.Message
>> End Try
>>> Thanks,
>> Mark
>>>

Nov 18 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.