C# 9.0 Pocket Reference by Joseph Albahari & Ben Albahari

C# 9.0 Pocket Reference by Joseph Albahari & Ben Albahari

Author:Joseph Albahari & Ben Albahari [Joseph Albahari]
Language: eng
Format: epub
Publisher: O'Reilly Media, Inc.
Published: 2021-01-19T16:00:00+00:00


try { int x = 3, y = 0; Console.WriteLine (x / y); } catch (DivideByZeroException) { Console.Write ("y cannot be zero. "); } // Execution resumes here after exception...

Note

This is a simple example to illustrate exception handling. We could deal with this particular scenario better in practice by checking explicitly for the divisor being zero before calling Calc.

Exceptions are relatively expensive to handle, taking hundreds of clock cycles.

When an exception is thrown within a try statement, the CLR performs a test:

Does the try statement have any compatible catch blocks?

If so, execution jumps to the compatible catch block, followed by the finally block (if present), and then execution continues normally.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.