Debugger and Exception in static class initializer

G

Guest

Set "Common Language Runtime Exceptions: When Exception is Thrown" to "Continue"
Execute button1_Click
Debugger should break on line "SHOULD BREAK HERE" and not on line "SHOULD NOT BREAK HERE"
Debugger breaks on correct line for normal class initializers

class Ab

static Abc(

throw new System.Exception("SHOULD NOT BREAK HERE")



private void button1_Click(object sender, System.EventArgs e
{
tr

Abc abc = new Abc()

catc

MessageBox.Show("SHOULD BREAK HERE")
 
G

Guest

Hi Charles,

I have reproduced out your issue. I will spend some time to do some
research on it.

I will reply to you ASAP. Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Hi Charles

I think the problem may be that the static constructor is initialized too
early, and before the try{} block is entered, the exception is thrown. So
the Debuger will trap the exception for you.

But I am not confirm this now. I will still spend some more time on it,
please wait for my further reply.

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Hi Charles,

Sorry for letting you wait for so long time.

After do a lot of research and consulting, now, I will reply to you.

The static constructor can be called before the first access of static
field. And it could run much earlier. So in our case, when the static
constructor is accessed, it has not entered the try{} block, so the
exception will be treated as a unhandled exception. So the debugger will
catch the exception for you.

To determine this, you should change your application's Exception setting
of "If the exception is not handled" to "Continue", then you debugger will
not catch the exception for you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Hi charles,

Does my reply make sense to you?

If you still have any concern, please feel free to feedback, I will help
you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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