G
Guest
Hi! I have an odd problem with an exception that doesn't arrive properly. I
have a situation similiar to this:
class MyClass
{
public Object MyProperty
{
get
{
return myProperty;
}
set
{
Object oldValue = myProperty;
myProperty = value;
if(OnPropertyChanged != null)
{
try
{
OnPropertyChanged(...);
} catch (Exception)
{
myProperty = oldValue;
throw;
}
}
}
}
}
In the invokation list of OnPropertyChanged I (intentionally; invalid
property value) throw a custom exception (derived from ApplicationException),
but the exception I catch above is a MissingMethodException! My exception
just vanishes into thin air and gets replaced by that exception. This is not
good, since my exception contains information that I need to present to the
user.
And what is ever stranger is that the value of MyProperty will change to the
new value, even though I restore that value (myProperty = oldValue).
What am I doing wrong? I'm looking at the code being executed (debugger) and
can actually see that the line "myProperty = oldValue" executes properly. Yet
the value of the property will be the value that caused the exception. The
property is not changed elsewhere either.
I haven't been using C# very long, so I don't know the mechanics of the
language. For instance, can objects be copied? This would still not explain
the exception, but at least it would explain why the property doesn't get
restored.
Thanks in advance,
Nille
have a situation similiar to this:
class MyClass
{
public Object MyProperty
{
get
{
return myProperty;
}
set
{
Object oldValue = myProperty;
myProperty = value;
if(OnPropertyChanged != null)
{
try
{
OnPropertyChanged(...);
} catch (Exception)
{
myProperty = oldValue;
throw;
}
}
}
}
}
In the invokation list of OnPropertyChanged I (intentionally; invalid
property value) throw a custom exception (derived from ApplicationException),
but the exception I catch above is a MissingMethodException! My exception
just vanishes into thin air and gets replaced by that exception. This is not
good, since my exception contains information that I need to present to the
user.
And what is ever stranger is that the value of MyProperty will change to the
new value, even though I restore that value (myProperty = oldValue).
What am I doing wrong? I'm looking at the code being executed (debugger) and
can actually see that the line "myProperty = oldValue" executes properly. Yet
the value of the property will be the value that caused the exception. The
property is not changed elsewhere either.
I haven't been using C# very long, so I don't know the mechanics of the
language. For instance, can objects be copied? This would still not explain
the exception, but at least it would explain why the property doesn't get
restored.
Thanks in advance,
Nille