throw statement inside a catch block continually caught be same catchblock?

T

Tracy Bannon

I am using VS2008 with C# to write a demo app. I have just begun to
add exception management.

I added a simple proof of concept method shown below where I catch an
exception and propogate it using throw.

When I run this in the IDE, with a break point set on the catch
statement and on the throw statement, I find that the throw statement
"appears"
to be caught by the same catch block. Note: The calling routine does
not have any retry logic.

The IDE stops on the throw statement and shows the exception handling
dialog box.


public void UpdateTeamMember(TeamMember teamMember)
{

try
{
//TODO: remove this testing
throw new Exception
("BusinessComponentTestException");

catch (Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex,
"BusinessComponentNotifyRethrow");
if (rethrow)
{
throw;
}

}

}


(BTW, I'm using EL3.1 and my exception handling policy returns
true)

I'm a little perplexed. I must have a visual studio IDE setting or
option incorrect?
 
S

Steve S

Hi Tracey
It sounds like the throw in the catch block isnt being handled anywhere in
your code, so you may be getting an exception is unhandled message? If
thats the case then the calling method needs to handle the exception thrown
in your catch block.

Cheers
Steve
 
F

Family Tree Mike

Tracy Bannon said:
I am using VS2008 with C# to write a demo app. I have just begun to
add exception management.

I added a simple proof of concept method shown below where I catch an
exception and propogate it using throw.

When I run this in the IDE, with a break point set on the catch
statement and on the throw statement, I find that the throw statement
"appears"
to be caught by the same catch block. Note: The calling routine does
not have any retry logic.

The IDE stops on the throw statement and shows the exception handling
dialog box.


public void UpdateTeamMember(TeamMember teamMember)
{

try
{
//TODO: remove this testing
throw new Exception
("BusinessComponentTestException");

catch (Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex,
"BusinessComponentNotifyRethrow");
if (rethrow)
{
throw;
}

}

}


(BTW, I'm using EL3.1 and my exception handling policy returns
true)

I'm a little perplexed. I must have a visual studio IDE setting or
option incorrect?


Look at the "Debug" menu, and select "Exceptions". I think there is an
option to stop on thrown exceptions there.
 
T

Tracy Bannon

Hi Tracey
It sounds like the throw in the catch block isnt being handled anywhere in
your code, so you may be getting an exception is unhandled message?  If
thats the case then the calling method needs to handle the exception thrown
in your catch block.

Cheers
Steve



My "harness" does have try/catch handling but appears to be on a
different thread somehow. Here are more details: My application is a
WPF application using the Prism (composite guidance).

My app.xaml.cs (which is the entry point into the app) has an outer
try/catch for handling however, it was never reached. The app.xaml.cs
invokes a bootstrapper class (bootstrapper.run).

I added an UnhandledException event handler in the app.xaml.cs and
that allowed me to catch the exception.

The bootstrapper sets up the entire application, WPF views,
presenter, models etc. I'm certain that I will have more questions on
this as I continue working with it.

Thanks for pointing me in the right direction.
 

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