From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/fileexception/index.html | 182 +++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 files/zh-cn/web/api/fileexception/index.html (limited to 'files/zh-cn/web/api/fileexception') diff --git a/files/zh-cn/web/api/fileexception/index.html b/files/zh-cn/web/api/fileexception/index.html new file mode 100644 index 0000000000..a888b6b6b3 --- /dev/null +++ b/files/zh-cn/web/api/fileexception/index.html @@ -0,0 +1,182 @@ +--- +title: FileException +slug: Web/API/FileException +translation_of: Web/API/FileException +--- +
{{APIRef("File System API")}} {{Non-standard_header}}
+ +

在 文件系统 API 中, FileException 表示错误条件,你可能在使用同步 API 访问文件系统时遇到。它扩展了 FileException 接口,在 File Writer 中描述,并添加了几个新的错误代码。

+ +

基本概念

+ +

同步 API 没有错误回调,这使其难以捕获错误。和这个 API 一起使用 WebWorkers 的额外复杂性,使得调试更具有挑战性。为了使事情简化,将你的工作器代码包在 try/catch 里面。当错误发生时,使用 postMessage() 将它们转发给主应用,像这样:

+ +
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);
+} 
+ +

示例代码取自 HTML5Rocks

+ +

属性

+ + + + + + + + + + + + + + + + +
AttributeTypeDescription
codeunsigned short用于该条件的最合适的错误代码。
+ +

常量

+ +

{{Note("不要依赖于常量的数值,它可能随着规范改动而改动。使用常量名称来代替。")}}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
常量描述
ENCODING_ERR5URL 格式错误。确保 URL 是完整和有效的。
INVALID_MODIFICATION_ERR9请求的改动是不允许的。无效改动包括将目录移动到它的子目录中,或者将文件移动到它的父目录中,而没有修改它的名称。
INVALID_STATE_ERR7在接口对象的当前状态上,不能执行操作。例如,缓存在接口对象中的状态,自从上次从磁盘读取之后发生改变。
NO_MODIFICATION_ALLOWED_ERR6底层文件系统的状态阻止任何文件或者目录的写入。
NOT_FOUND_ERR1在操作执行时,所需文件或者目录无法找到。例如,打开了不存在的文件。
NOT_READABLE_ERR4 +

文件或者目录不能读取,通常由于权限问题,出现在获取文件引用之后(例如,文件或者目录当前由另一个应用锁住)。

+
PATH_EXISTS_ERR12路径相同的文件或者目录已存在。
QUOTA_EXCEEDED_ERR10 +

没有足够的剩余空间,或者存储器配额已达到,并且用户拒绝向数据库提供更多空间。

+
SECURITY_ERR2 +

拒绝文件访问,由于下列原因之一:

+ +
    +
  • 在 Web 应用中访问文件是不安全的。
  • +
  • 文件资源上有过多调用。
  • +
  • 其它未规定的安全错误代码或情况。
  • +
+
TYPE_MISMATCH_ERR11用户尝试检索文件或者目录,但是找到的条目类型错误。例如,应用正在访问 DirectoryEntry ,当用户请求 FileEntry 的时候。
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support13{{property_prefix("webkit")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support{{CompatNo}}0.16 {{property_prefix("webkit")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

另见

+ +

规范:{{spec("http://dev.w3.org/2009/dap/file-system/pub/FileSystem/", "文件 API:目录和系统规范", "WD")}}

+ +

参考:文件系统 API

+ +

简介:文件系统 API 的基本概念

-- cgit v1.2.3-54-g00ecf