Skip to main content

Part of the book series: Undergraduate Topics in Computer Science ((UTICS))

  • 10k Accesses

Abstract

Until this point we have used assert statements to ensure that a condition required by the code to generate correct output is met. For example, we might check that a number that we were going to take the square root of is non-negative, and trip an assertion if this condition were not met. Whilst this approach is very useful as it pinpoints errors, it is rather inflexible as it terminates the code at the instant that an assertion is tripped. We would much rather the code instead made some attempt to fix the problem itself, if that were possible, warned us of the possible effects of the fix if necessary, and then carried on executing. This is possible through the use of exceptions, which are the focus of this chapter.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 29.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Jonathan Whiteley .

Rights and permissions

Reprints and permissions

Copyright information

© 2012 Springer-Verlag London Limited

About this chapter

Cite this chapter

Pitt-Francis, J., Whiteley, J. (2012). Errors and Exceptions. In: Guide to Scientific Computing in C++. Undergraduate Topics in Computer Science. Springer, London. https://doi.org/10.1007/978-1-4471-2736-9_9

Download citation

  • DOI: https://doi.org/10.1007/978-1-4471-2736-9_9

  • Publisher Name: Springer, London

  • Print ISBN: 978-1-4471-2735-2

  • Online ISBN: 978-1-4471-2736-9

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics