Cant catch an exception

G

Guest

Apologies if this is the wrong forum for this question.

Could anyone explain why this exception code is not working?

The exception is thrown, but then reported as unhandled. The try catch in
Main seems to be being ignored???

The exception being reported is a generic System.Exception, nothing exotic.

This is only an illustration by the way :)

public class A
{
Public void Bla()
{
if (something) { throw new Exception(“An Errorâ€); }
}
}

public class B
{
static void Main()
{
// A collection of A's exists
foreach (A item in ACollection)
{
try
{
item.Bla();
}
catch
{
MessageBox.Show(“Caughtâ€);
}
}
}
}

Any help much appreciated.
 

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