0

Is there anything like exception code? that i can know that on different languages operation system i can recognize the same exception?

I need to recognize 'Acces to the COMn Port is denied' and then do some action, is that possible? has this exception any specified type?

1
  • What have you tried? Also being a bit more specific as to what you're trying to do would be helpful. Commented Feb 29, 2012 at 10:34

2 Answers 2

2

From the sounds of it you will be getting a System.UnauthorizedAccessException (this assumption has been made from Googling the error message and finding this forum). To handle this, you would need to use catch clauses in a try-catch statement that are specific to this exception type. So, in C# you would do something like:

try
{
    // ... Run some code that might cause the error in question ...
}
catch (System.UnauthorizedAccessException ex)
{
    // ... Run some code that handles the error in question ...
}
Sign up to request clarification or add additional context in comments.

Comments

0

There is no concept of a global exception code in .NET -- and there really could never be, since it implies that every author of every exception class on the planet would have to collaborate in order to choose codes.

You also cannot assume that a particular message signals an exception of a particular type, since the message can (in the general case) be freely chosen at the throw site.

You could do a type switch on exception.GetType() to find what the runtime type of an exception is, but that is not guaranteed to be a solution (it depends on what was actually thrown, which could be a vanilla System.Exception for all we know).

What exactly are you trying to achieve?

1 Comment

I need to work with devices which like to broke COM port and then only restart of the machine can help, i need to recognize it and react.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.