95

Possible Duplicate:
how to use Java-style throws keyword in C#?

i have a function where an exception occurs say for example

private void functionName() throws Exception
{
   // some code that might throw an exception
}

thanks!

Community
  • 1
  • 1

3 Answers3

148

No, because there are no checked exceptions in C#

If you are trying to document exceptions that are thrown, use the standard xml documentation

/// <exception cref="InvalidOperationException">Why it's thrown.</exception>
Dilum Ranatunga
  • 13,254
  • 3
  • 41
  • 52
  • 2
    I noticed that the text I write in the exception element is not shown next to the exception in the Intellisense popup for the method. Do you know where it shows up? – jbb Jul 26 '17 at 14:21
19

No. There is no such construct in c#. But you can add the comment to your method like this /// <exception cref="Exception"></exception> and it will be visible in IntelliSense

fedotoves
  • 757
  • 6
  • 7
6

Unfortunately there isn't, and it can be a pain. The remedy is to be more careful with the exceptions that your code throws and how you handle errors.

Alan Delimon
  • 817
  • 7
  • 14