Skip to main content

Errors, Exceptions and Testing

  • Chapter
  • First Online:
Guide to Scientific Computing in C++

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

  • 215k 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 is one focus of this chapter. The second focus of this chapter is the use of suitable testing techniques to allow software to be developed in a sustainable manner.

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 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    If you were to use the C version of the trigonometry functions, rather than the C++ one, then you will find that atan2(0.0,0.0) gives no error and is defined to be 0.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Joe Pitt-Francis .

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Springer International Publishing AG, part of Springer Nature

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Pitt-Francis, J., Whiteley, J. (2017). Errors, Exceptions and Testing. In: Guide to Scientific Computing in C++. Undergraduate Topics in Computer Science. Springer, Cham. https://doi.org/10.1007/978-3-319-73132-2_9

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-73132-2_9

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-73131-5

  • Online ISBN: 978-3-319-73132-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics