S.P
S.P

Reputation: 73

How can I report exceptions in C#?

I have this code in Java, that I used to report exceptions (throws FileNotFoundException, IOException, ClassNotFoundException).

Example:

private void functionName() throws FileNotFoundException, IOException, ClassNotFoundException{}

I need to do this in C#, how can I do that?

Upvotes: 6

Views: 212

Answers (1)

TheCrimulo
TheCrimulo

Reputation: 461

It's pretty simple. In C#, you can't directly use a throws statement, because there isn´t. You may want to use this code:

    private void functionName(){ throw new IOException();}

This throws an IOException. As IOException being a class, you need to create a new one, with new statement.

Upvotes: 1

Related Questions