Try/Catch problem

B

bad_boyu

Hello,
I have the following code:

try
{
Salarii.Editors.AngajatiNewFrm _angNewFrm = new
Salarii.Editors.AngajatiNewFrm();
_angNewFrm.Connection = this.Connection;
_angNewFrm.ShowInTaskbar = false;
_angNewFrm.ShowDialog();
_angNewFrm.Dispose();
}
catch ( Exception ex )
{
Salarii.Exceptions.ExceptionFrm frm = new
Salarii.Exceptions.ExceptionFrm();
frm.Exc = ex;
frm.ShowDialog();
frm.Dispose();
}

This only a part from a big project.
My problem is that: if I run the application from Visual Studio than if
there is an error in try block than the exception is catch and my
Exceptions Form is displayed, but if I run the generated executable and
I produce the same error in try block than my Exception form is NOT
displayed. I am talking about the same error! I tried to put a
MessageBox in catch block, but is displayed only if I run from Visual
Studio.

Can somebody help me with this?

Thanks in advance!
Best regards,
O
 
N

Nicholas Paldino [.NET/C# MVP]

O,

I would guess that an exception is being thrown in the catch block. I
would put some code around there to determine what is going on.

Also, you might want to use the using statement as well. There is no
reason you should have to manually call Dispose on either of the forms.
 
S

sloan

try
{
Salarii.Editors.AngajatiNewFrm _angNewFrm = new
Salarii.Editors.AngajatiNewFrm();
_angNewFrm.Connection = this.Connection;
_angNewFrm.ShowInTaskbar = false;
_angNewFrm.ShowDialog();
_angNewFrm.Dispose();
}
catch ( Exception ex )
{
try
{
Salarii.Exceptions.ExceptionFrm frm = new
Salarii.Exceptions.ExceptionFrm();
frm.Exc = ex;
frm.ShowDialog();
frm.Dispose();


}
catch (Exception anotherEx)
{
MessageBox.Show(anotherEx.Message);
}



You'll probably find it like this.............. (aka, put a second
try/catch)


You can also write up a "starter" EntryPoint class like this:



Add a new Class .. called EntryPoint.cs

public class EntryPoint
{

public static void Main(string[] args)
{
try
{
Application.Run (new MainApplicationStartupForm());
}
catch (Exception ex)
{
MessageBox.Show("Unhandled exception: " + ex.Message);
}
}


}


You'll be able to recover better using the EntryPoint.cs class.
 
N

Nick Malik [Microsoft]

One other place to look...
what if the bug is in the dialog form itself.

It is entirely possible that your form load event has some bug in it that
doesn't show up in VS but does show up in an EXE environment. In that case,
the form is being called, but it errors out before it can show. Since you
are already in the last statements of a catch block, you wouldn't see the
effect. It would appear as though the form never opened.

Look in your code for the form itself.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 

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