Exception Text

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I have a c# program for compacting msaccess databases and I’m now setting
up the exception handling.

For 2 different conditions I get the following messages.

System.Runtime.InteropServices.COMException (0x80040E4D): Not a valid
account name or password.

System.Runtime.InteropServices.COMException (0x80004005): You attempted to
open a database that is already opened exclusively by user 'Test1' on machine
'Dta-TRP'. Try again when the database is available.

I need to show a customized message to show the exception. Is there anyway
to get the above exception text so that I can modify it slightly?

Thanks in advance.
 
check out the System.Exception object

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemExceptionClassTopic.asp

Most exception will be derived from this base class and it providers several
properties - Message, Source, InnerException, StackTrace etc.

The exception type below (System.Runtime.InteropServices.COMException) will
automatically have these properties so you will be able to access the
exception message using the 'Message' property.

HTH
Ollie Riches
http://www.phoneanalyser.net

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.
 
I've not tested it, but try the following

try
{
// your failing code in here
}
catch (System.Runtime.InteropServices.COMException exception)
{
switch ((uint)exception.ErrorCode)
{
case 0x80040E4D:
// handle error yourself
break;
case 0x80004005:
// handle error yourself
break;
default:
// otherwise rethrow the original exception
throw(exception);
}
}

Regards,
Phil.
 
Back
Top