CS 18000 Lecture Notes - Lecture 10: File Descriptor, Call Stack, Null Pointer

21 views6 pages

Document Summary

What to do when an error occurs: old style: return an error code , caller must check on each call. Requires a special value to indicate error: example: Open( file. txt ) in c returns a file descriptor that allows reading from the file. Returns -1 (an invalid file descriptor) if open fails. Programmer must remember to check for -1. Java approach: exceptions: write code without worrying about checking for errors, when an error is detected, an exception is thrown . Java system stops execution of the current method. Searches for an exception handler to deal with the problem: search begins in the current method and continues to. Caller -> caller"s caller -> caller"s caller"s caller -> Catching an exception: basic syntax: basic syntax of the try-catch statement try { statements-that-might-throw-exception; } catch (exception e) { statements-to-recover-from-exception: note: exception is a class name, not a reserved word; e is an object reference.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents