Error Handling

K

Kimochi

I got this error in my programm
how do i skip this error? thax

An unhandled exception of
type 'System.NullReferenceException' occurred in
system.windows.forms.dll

Additional information: Object reference not set to an
instance of an object.
 
P

Peter Jausovec

Hi,

It would be much easier if you posted the line where you get this error.
 
D

Dmitriy Lapshin [C# / .NET MVP]

try
{
// The offending code here.
}
catch(NullReferenceException)
{
}
 
G

Guest

this is my code

private void menuItem1_Click(object sender,
System.EventArgs e)
{
MessageBox.Show(ActiveMdiChild.Text);
}

ihave this function in my menu
it works if one of the form is open or active
if none of the child form is active it will prompt the
error. how do i handle it?
 
S

Shiva

Perhaps, you can check whether any child form is active before accessing it:

if (ActiveMdiChild == null)
MessageBox.Show ("No active MDI child");
else
MessageBox.Show(ActiveMdiChild.Text);

this is my code

private void menuItem1_Click(object sender,
System.EventArgs e)
{
MessageBox.Show(ActiveMdiChild.Text);
}

ihave this function in my menu
it works if one of the form is open or active
if none of the child form is active it will prompt the
error. how do i handle it?
 
G

Guest

I have try that before but still cannot works
anyway ive try the

try and catch and it can skip the errors

thax you for the help
 

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