How to get the last error message ?

  • Thread starter Thread starter Mr. X.
  • Start date Start date
How can I get the last error message string (& id) ?

Like VB's Err.LastDLLError? If that's not what you mean, show us the
corresponding VB code you're trying to convert.
 
Try {
....
}
Catch {
MyMethod();
}

....
and in other code :
MyMethod()
{
MessageBox.show(Convert.ToString(err.number)); // err.number is the
error-number on catch (like VB.NET). what should I write instead?
MessageBox.show(err.Message); // err.message is the error message on
catch. What should I write instead?
}

Thanks :)
 
Try {
...
}
Catch {
MyMethod();
}

...
and in other code :
MyMethod()
{
MessageBox.show(Convert.ToString(err.number)); // err.number is the
error-number on catch (like VB.NET). what should I write instead?
MessageBox.show(err.Message); // err.message is the error message on
catch. What should I write instead?
}

You need to pass the error details to MyMethod(). Which mean you need to
catch them too:

try
{
...
}
catch (Exception ex)
{
MyMethod(ex);
}

C# has no equivalent to VB's Err. Also, most .NET exceptions don't have an
associated error number. It's the type of exception (IOException,
ArgumentNullException, etc.) that is considered important, not a code.
 
Back
Top