Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 47962 of FileException

  • Revision slug: DOM/File_API/File_System_API/FileException
  • Revision title: FileException
  • Revision id: 47962
  • Created:
  • Creator: grendel
  • Is current revision? No
  • Comment Clean up; 1 words added, 2 words removed

Revision Content

DRAFT
This page is not complete.

In the File System API, a FileException object represents error conditions that you might encounter while accessing the file system using the synchronous API. It extends the FileException interface described in File Writer and adds several new error codes.

Basic concepts

Synchronous APIs do not have error callbacks, which makes it difficult to catch errors. The added complexity of using WebWorkers with this API makes debugging even more challenging. To simplify things a bit, wrap your worker code in a try/catch. When errors occur, forward them to the main app using postMessage() as in the following:

function onError(e) {
   postMEssage('ERROR:' + e.toString());
}

try {
   //Error is thrown if "log.txt" already exists.
var fileEntry = fs.root.getFile('log.txt', {create: true, exclusive:true}0;
} catch (e) {
   onErrror(e);
} 

The sample code was borrowed from HTML5Rocks

Attribute

Attribute Type Description
code unsigned short The most appropriate error code for the condition.

Constants

{{ Note("Do not rely on the numeric values of the constants, which might change as the specifications continue to change. Use the constant names instead.") }}

Constant Value Description
ENCODING_ERR 5 The URL is malformed. Make sure that the URL is complete and valid.
INVALID_MODIFICATION_ERR 9 The modification requested is not allowed. Examples of invalid modifications include moving a directory into its own child or moving a file into its parent directory without changing its name.
INVALID_STATE_ERR 7 The operation cannot be performed on the current state of the interface object. For example, the state that was cached in an interface object has changed since it was last read from disk.
NO_MODIFICATION_ALLOWED_ERR 6 The state of the underlying file system prevents any writing to a file or a directory.
NOT_FOUND_ERR 1 A required file or directory could not be found at the time an operation was processed. For example, a file did not exist but was being opened.
NOT_READABLE_ERR 4

The file or directory cannot be read, typically due to permission problems that occur after a reference to a file has been acquired (for example, the file or directory is concurrently locked by another application).

PATH_EXISTS_ERR 12 The file or directory with the same path already exists.
QUOTA_EXCEEDED_ERR 10

Either there's not enough remaining storage space or the storage quota was reached and the user declined to give more space to the database.

SECURITY_ERR 2

Access to the files were denied for one of the following reasons:

  • The files might be unsafe for access within a Web application.
  • Too many calls are being made on file resources.
  • Other unspecified security error code or situations.
TYPE_MISMATCH_ERR 11 The user has attempted to look up a file or directory, but the Entry found is of the wrong type. For example, the app is accessing a DirectoryEntry when the user is requesting a FileEntry.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 13{{ property_prefix("webkit") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatNo() }} 0.16 {{ property_prefix("webkit") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}

See also

Specification: {{ spec("https://dev.w3.org/2009/dap/file-system/pub/FileSystem/", "File API: Directories and System Specification", "WD") }}

Reference: File System API

Introduction: Basic Concepts About the File System API

Revision Source

<div style="margin: 1em 0px; padding: 1em; background-color: rgb(255, 255, 204); text-align: center;"><strong>DRAFT</strong> <div style="font-size: x-small;">This page is not complete.</div>
</div>
<p>In the <a href="/en/DOM/File_API/File_System_API" title="en/DOM/File_API/File_System_APIB">File System API</a>, a <code>FileException </code>object represents error conditions that you might encounter while accessing the file system using the synchronous API. It extends the FileException interface described in <a class="external" href="https://dev.w3.org/2009/dap/file-system/pub/FileSystem/#bib-FILE-WRITER">File Writer</a> and adds several new error codes.</p>
<h2>Basic concepts</h2>
<p>Synchronous APIs do not have error callbacks, which makes it difficult to catch errors. The added complexity of using <a href="/en/DOM/Worker" title="en/DOM/Worker">WebWorkers</a> with this API makes debugging even more challenging. To simplify things a bit, wrap your worker code in a try/catch. When errors occur, forward them to the main app using <code>postMessage()</code> as in the following:</p>
<pre class="brush: js">function onError(e) {
   postMEssage('ERROR:' + e.toString());
}

try {
   //Error is thrown if "log.txt" already exists.
var fileEntry = fs.root.getFile('log.txt', {create: true, exclusive:true}0;
} catch (e) {
   onErrror(e);
} </pre>
<p>The sample code was borrowed from <a class="external" href="https://www.html5rocks.com/en/tutorials/file/filesystem-sync/">HTML5Rocks</a></p>
<h2>Attribute</h2>
<table class="standard-table"> <thead> <tr> <th scope="col">Attribute</th> <th scope="col">Type</th> <th scope="col">Description</th> </tr> </thead> <tbody> <tr> <td><a name="attr_code"><code>code</code></a></td> <td><code>unsigned short</code></td> <td>The most appropriate error code for the condition.</td> </tr> </tbody>
</table>
<h2>Constants</h2>
<p>{{ Note("Do not rely on the numeric values of the constants, which might change as the specifications continue to change. Use the constant names instead.") }}</p>
<table class="standard-table"> <thead> <tr> <th scope="col">Constant</th> <th scope="col">Value</th> <th scope="col">Description</th> </tr> <tr> <td><code><a name="NON_TRANSIENT_ERR">ENCODING_ERR</a></code></td> <td>5</td> <td>The URL is malformed. Make sure that the URL is complete and valid.</td> </tr> <tr> <td><code><a name="NON_TRANSIENT_ERR">INVALID_MODIFICATION_ERR</a></code></td> <td>9</td> <td>The modification requested is not allowed. Examples of invalid modifications include moving a directory into its own child or moving a file into its parent directory without changing its name.</td> </tr> <tr> <td><code><a name="CONSTRAINT_ERR">INVALID_STATE_ERR</a></code></td> <td>7</td> <td>The operation cannot be performed on the current state of the interface object. For example, the state that was cached in an interface object has changed since it was last read from disk.</td> </tr> <tr> <td><code><a name="VER_ERR">NO_MODIFICATION_ALLOWED_ERR</a></code></td> <td>6</td> <td>The state of the underlying file system prevents any writing to a file or a directory.</td> </tr> <tr> <td><code><a name="NOT_FOUND_ERR">NOT_FOUND_ERR</a></code></td> <td>1</td> <td>A required file or directory could not be found at the time an operation was processed. For example, a file did not exist but was being opened.</td> </tr> </thead> <tbody> <tr> <td><code><a name="NON_TRANSIENT_ERR">NOT_READABLE_ERR</a></code></td> <td>4</td> <td> <p>The file or directory cannot be read, typically due to permission problems that occur after a reference to a file has been acquired (for example, the file or directory is concurrently locked by another application).</p> </td> </tr> <tr> <td><code><a name="TIMEOUT_ERR">PATH_EXISTS_ERR</a></code></td> <td>12</td> <td>The file or directory with the same path already exists.</td> </tr> <tr> <td><code><a name="QUOTA_ERR">QUOTA_EXCEEDED_ERR</a></code></td> <td>10</td> <td> <p>Either there's not enough remaining storage space or the storage quota was reached and the user declined to give more space to the database.</p> </td> </tr> <tr> <td><code><a name="SECURITY_ERR">SECURITY_ERR</a></code></td> <td>2</td> <td> <p>Access to the files were denied for one of the following reasons:</p> <ul> <li>The files might be unsafe for access within a Web application.</li> <li>Too many calls are being made on file resources.</li> <li>Other unspecified security error code or situations.</li> </ul> </td> </tr> <tr> <td><code><a name="READ_ONLY_ERR">TYPE_MISMATCH_ERR</a></code></td> <td>11</td> <td>The user has attempted to look up a file or directory, but the Entry found is of the wrong type. For example, the app is accessing a DirectoryEntry when the user is requesting a FileEntry.</td> </tr> </tbody>
</table>
<h2 name="Browser_Compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari (WebKit)</th> </tr> <tr> <td>Basic support</td> <td>13{{ property_prefix("webkit") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Chrome for Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatNo() }}</td> <td>0.16 {{ property_prefix("webkit") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatNo() }}</td> </tr> </tbody> </table>
</div>
<h2>See also</h2>
<p>Specification: {{ spec("https://dev.w3.org/2009/dap/file-system/pub/FileSystem/", "File API: Directories and System Specification", "WD") }}</p>
<p>Reference: <a href="/en/DOM/File_API/File_System_API" title="en/DOM/File_API/File_System_API">File System API</a></p>
<p>Introduction: <a href="/en/DOM/File_APIs/Filesystem/Basic_Concepts_About_the_Filesystem_API" title="en/DOM/File_APIs/Filesystem/Basic_Concepts_About_the_Filesystem_API">Basic Concepts About the File System API</a></p>
Revert to this revision