flâneur — a map of the web's best reading

22. Exception - CS2030S Programming Methodology II

nus-cs2030s.github.io · 3,303 words · saved by 1 readers

One of the nuances of programming is having to write code to deal with exceptions and errors. Consider writing a method that reads in a single integer value from a file. Here are some things that could go wrong: In C, we usually have to write code like this: Out of the lines above, only TWO lines correspond to the actual task of opening and reading in a file, the others are for exception checking/handling. The actual tasks are interspersed between exception checking code, which makes reading and understanding the logic of the code difficult. The examples above also have to return different values to the calling method, because the calling method may have to do something to handle the errors. Note that the POSIX API has a global variable errno that signifies the detailed error. First, we have to check for different errno values and react accordingly (we can use perror, but that has its limits). Second, errno is global, and using a global variable is a bad practice. In fact, the code abo

Unit 22: Exceptions After this unit, students should: understand about handling java exceptions and how to use the try - catch - finally blocks understand the hierarchy of exception classes and the difference between checked and unchecked exceptions be able to create their own exceptions understand the control flow of exceptions be aware of good practices for exception handling One of the nuances of programming is having to write code to deal with exceptions and errors. Consider writing a method that reads in a single integer value from a file. Here are some things that could go wrong: The fil

Explore this link on the map →

saved by

related reading