Hi,
Gigasoft wrote:I think //... is the important part here.
Ok:
Code: Select all
retry:
status = file.Error();
switch (status)
{
case OK:
break;
case FileNotFound:
create_default_file();
goto retry;
case FileLocked:
sleep(2); /* Wait for other process to finish using it */
goto retry;
case FileAccessNotPermitted:
do_dialog_box("ERROR: File permission problem.");
exit(1);
default:
do_dialog_box("ERROR: An unknown error (%s) occurred while trying to write to the log file", system.getErrorString(status) );
exit(1);
}
Gigasoft wrote:It usually doesn't matter to an application how something went wrong - there is nothing it can do about it anyway.
That depends what the application is and how good the application is. A kernel shouldn't be designed for one specific application, and therefore should be design for a wide range of applications including applications that do want/need the error codes.
Who decides when a condition is an error anyway? Think about something this:
Code: Select all
printf("Please remove the CD-ROM!");
do {
status = open("/dev/cd");
switch(status) {
OK:
/* "OK" is an error (CD not removed) */
close("/dev/cd");
....
} while(status != NO_MEDIA); /* "No media error" indicates everything is OK (CD-ROM successfully removed) */
Gigasoft wrote:As for receipt printers, they normally don't return error codes. Instead, they report their status when there is a change or when requested by the user, so it doesn't make sense for the system to make up an error code.
One of the reasons for kernel and device drivers to exist in the first place is to provide usable abstractions between applications and the hardware. For example, so that an application can just print something; without caring if it's using a colour ink jet printer, using a laser printer, having "print" redirected to remote service/printer on the network, having "print" redirected to a virtual device that actually generates a PDF file instead of printing anything, using a dot matrix receipt printer, etc (and without caring which manufacturer and model printer, or if the hardware itself handles postscript or bitmap data or only ASCII characters, or if it's connected via. USB or ethernet or parallel or serial). If the OS fails to provide useful abstractions then the OS is a worthless piece of crud.
Of course this abstraction means that you need to map various conditions (that may or may not be possible for specific printers) to a common set of error codes. For example, you might have "ERROR_NO_INK" or "ERROR_NETWORK_TIMEOUT" which don't make sense for a thermal/laser printer, but should still exist so that applications can be designed to support other types of printers without changes.
Gigasoft wrote:I am guessing that regardless of what the problem is, it is handled by displaying something like "Out of order - Please contact the staff" on the screen and halting.
I'm guessing you're talking about one specific application (e.g. a process that sits on top of the OS and handles an ATM machine), and forgot all about the OS underneath.
Cheers,
Brendan