FileException - Web APIs 编辑

Non-standard

This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

Obsolete

This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

In the File System API, a FileExceptionobject 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

AttributeTypeDescription
codeunsigned shortThe 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.
ConstantValueDescription
ENCODING_ERR5The URL is malformed. Make sure that the URL is complete and valid.
INVALID_MODIFICATION_ERR9The 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_ERR7The 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_ERR6The state of the underlying file system prevents any writing to a file or a directory.
NOT_FOUND_ERR1A 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_ERR4

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_ERR12The file or directory with the same path already exists.
QUOTA_EXCEEDED_ERR10

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_ERR2

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_ERR11The 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

BCD tables only load in the browser

See also

Specification: File API: Directories and System SpecificationWD

Reference: File System API

Introduction: Basic Concepts About the File System API

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:50 次

字数:6347

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文