Join Peggy Fisher for an in-depth discussion in this video Error handling, part of Up and Running with C++.
- View Offline
- Exercise Files
…Most programming languages have code that helps handle unexpected errors.…It provides the programmer control over the exception, so…they can provide meaningful messages and avoid program interruption.…In C++, we're going to use the try-catch block.…We place this in our code in areas that might cause an…exception such as trying to read from a file that doesn't exist.…When an error occurs an exception is thrown or…raised, which is then caught by an exception handler.…Here's a simple program that tests to make sure we're not dividing by zero.…
In my program I'm only going to test through one kind…of error, so I have int error code equals 10.…I'm going to ask the user to enter in two…values, one for the numerator and one for the denominator.…Then I want to make sure before I go ahead…and divide that they didn't enter zero for the denominator.…So in my try block I have if denominator is equal…to zero I'm going to stop and throw an error code.…That error code is the code I define at the beginning of the program.…
- Downloading and exploring the C++ IDE
- Working with loops
- Using predefined functions
- Creating custom functions
- Creating and instantiating classes
- Working with external files
Skill Level Beginner
1. Getting Started
2. C++ Basics
3. Flow of Control
4. Classes and Objects
5. Data Structures
6. File Manipulation
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.