Last active
May 1, 2019 05:22
-
-
Save mvodep/0155c504bcefed395b644b8291a20506 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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