Skip to content

Instantly share code, notes, and snippets.

@mvodep
Last active May 1, 2019 05:22
Show Gist options
  • Save mvodep/0155c504bcefed395b644b8291a20506 to your computer and use it in GitHub Desktop.
Save mvodep/0155c504bcefed395b644b8291a20506 to your computer and use it in GitHub Desktop.
internal sealed class PhoneBook {
private String m_pathname; // path name of file containing the address book
// Other methods go here.
public String GetPhoneNumber(String name) {
String phone;
FileStream fs = null;
try {
fs = new FileStream(m_pathname, FileMode.Open);
// Code to read from fs until name is found goes here
phone = /* the phone # found */
}
catch (FileNotFoundException e) {
// Throw a different exception containing the name, and
// set the originating exception as the inner exception.
throw new NameNotFoundException(name, e);
}
catch (IOException e) {
// Throw a different exception containing the name, and
// set the originating exception as the inner exception.
throw new NameNotFoundException(name, e);
}
finally {
if (fs != null) {
fs.Close();
}
}
return phone;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment