Exceptions and Exception Handling

The exception-handling features of C# will be familiar to the Java programmer; the exception-handling syntax is predominantly the same, although the languages differ significantly in their exception declaration requirements.

Declaring Exceptions

There is no requirement, and no ability, in C# for a function member to programmatically declare the exceptions it might throw. The only way to do so is in the API documentation. This has two consequences:

  • Java developers are accustomed to methods explicitly declaring the checked exceptions they might throw. The absence of a throws declaration means that the programmer is more reliant on API documentation than on the compiler.

  • Interface members cannot specify which exceptions ...

Get C# for Java Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.