C# 5.0 Pocket Reference by Joseph Albahari & Ben Albahari

C# 5.0 Pocket Reference by Joseph Albahari & Ben Albahari

Author:Joseph Albahari & Ben Albahari
Language: eng
Format: epub
ISBN: 9781449339906
Publisher: O'Reilly Media


Throwing Exceptions

Exceptions can be thrown either by the runtime or in user code. Here, Display throws a System.ArgumentNullException:

static void Display (string name) { if (name == null) throw new ArgumentNullException ("name"); Console.WriteLine (name); }

Rethrowing an exception

You can capture and rethrow an exception as follows:

try { ... } catch (Exception ex) { // Log error ... throw; // Rethrow same exception }

Rethrowing in this manner lets you log an error without swallowing it. It also lets you back out of handling an exception should circumstances turn out to be outside what you expected.



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.