03.01.2015 Views

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5.8 Throwing Exceptions<br />

We may deliberately choose <strong>to</strong> cause an exception. We use the throw statement for<br />

this.<br />

We may define our own Exceptions and throw them.<br />

Choose one or neither of the below:<br />

• There is no point in doing this unless we carefully document the circumstances.<br />

If we cannot be bothered <strong>to</strong> do this we should not bother creating<br />

cus<strong>to</strong>m exceptions.<br />

• Exceptions are self‐documenting mechanisms. It is bad practice <strong>to</strong> throw<br />

someone else’s exception.<br />

5.9 Policy on when <strong>to</strong> catch and when <strong>to</strong> throw<br />

The business of which exceptions <strong>to</strong> catch is complex. There are often good reasons<br />

<strong>to</strong> not catch exceptions. An uncaught exception will propagate back up the stack.<br />

• The Cerebus system has a mechanism for dealing with exceptions.<br />

• Comment from Nick<br />

<strong>Intro</strong>duction <strong>to</strong> .NET<br />

Agilent .NET Course: Module 5, page 7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!