How to 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 this?

+6
source share
1 answer

It is pretty simple. In C #, you cannot directly use the throws operator because it does not exist. You can use this code:

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

This throws an IOException. Since IOException is a class, you need to create a new one, with a new expression.

+1
source

All Articles