File.error()

NES2+Syntax

							file.error()

Description

The error() method of the File object returns the operating system error code when an error occurs opening a file. This method returns 0 if there is no error, and –1 if the file you invoke the method on is not open.

Example

Listing 8.75 opens a file for reading. If there was a problem during this operation, the error is written to the user's page.

Listing 8.75 Using the error() Method to Access an Error to Write to the User's Page
 <SERVER> // Open a log file var myLog = new File("/data/logs/today.log"); // Open the log file for reading myLog.open("r"); if (myLog.error() == 0) { // Perform actions on file }else{ // Write out the error write('Error: ' + myLog.error()); // Clear the error ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.