Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I report exceptions in C#?

Tags:

c#

throws

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?

like image 400
S.P Avatar asked Dec 25 '15 21:12

S.P


1 Answers

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.

like image 65
TheCrimulo Avatar answered Oct 02 '22 12:10

TheCrimulo