|
Error CodesThe return value 0 from a method may show that there was some error, but not what the problem was. It is common to combine return values of this kind with a way to find out the nature of the problem. This can be done with special error codes, that your program can retrieve from somewhere. Lets look at this example, which opens a file on disk for reading: Stdio.File localfile = Stdio.File(); if(!localfile->open(file_name, "r")) { werror("Couldn't open '" + file_name + "'.\n"); werror(strerror(localfile->errno()) + " (errno = " + localfile->errno() + ").\n"); exit(1); } Some comments about this:
If the file couldn't be opened, the program's output will look something like this: Couldn't open 'foobar.txt'. No such file or directory (errno = 2). |
|||