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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.