Is there a throws keyword in C# like in Java?

C#JavaExceptionThrowThrows

C# Problem Overview


> 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!

C# Solutions


Solution 1 - C#

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>

Solution 2 - C#

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

Solution 3 - C#

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser677607View Question on Stackoverflow
Solution 1 - C#Dilum RanatungaView Answer on Stackoverflow
Solution 2 - C#fedotovesView Answer on Stackoverflow
Solution 3 - C#Alan DelimonView Answer on Stackoverflow