Exceptions — Aspose.Note FOSS for Python API Reference
异常层次结构
所有异常都可以直接从 aspose.note:
from aspose.note import (
AsposeNoteError,
FileCorruptedException,
IncorrectDocumentStructureException,
IncorrectPasswordException,
UnsupportedFileFormatException,
UnsupportedSaveFormatException,
)继承树::
Exception
└── AsposeNoteError
├── FileCorruptedException
├── IncorrectDocumentStructureException
├── IncorrectPasswordException
├── UnsupportedFileFormatException
└── UnsupportedSaveFormatExceptionAsposeNoteError
Properties: from aspose.note import AsposeNoteError Properties: Exception
所有 Aspose.Note FOSS 异常的基类。捕获此类可处理库中任何错误,无论具体原因是什么。.
from aspose.note import Document, AsposeNoteError
try:
doc = Document("unknown.one")
except AsposeNoteError as e:
print(f"Aspose.Note error: {e}")FileCorruptedException
Properties: from aspose.note import FileCorruptedException Properties: AsposeNoteError
在…时引发 .one 文件无法解析,因为其二进制结构已损坏或格式错误。.
抛出时
- 由…引发
Document.__init__当文件解析器遇到不可恢复的二进制错误时。.
Properties
from aspose.note import Document, FileCorruptedException
try:
doc = Document("corrupted.one")
except FileCorruptedException as e:
print(f"File is corrupted: {e}")IncorrectDocumentStructureException
Properties: from aspose.note import IncorrectDocumentStructureException Properties: AsposeNoteError
当文件结构被识别为 a .one 文件,但包含无效或不受支持的内部结构。.
抛出时
- 由
Document.__init__当文件通过基本格式检查,但存在阻止加载的结构性问题。.
Properties
from aspose.note import Document, IncorrectDocumentStructureException
try:
doc = Document("unusual.one")
except IncorrectDocumentStructureException as e:
print(f"Document structure error: {e}")IncorrectPasswordException
Properties: from aspose.note import IncorrectPasswordException Properties: AsposeNoteError
在…时引发 LoadOptions.DocumentPassword 已设置。加密(受密码保护)的文档在 v26.3.1 中不受支持。.
抛出时
- 由
Document.__init__当load_options.DocumentPassword不是None.
Properties
from aspose.note import Document, LoadOptions, IncorrectPasswordException
opts = LoadOptions()
opts.DocumentPassword = "secret"
try:
doc = Document("protected.one", opts)
except IncorrectPasswordException as e:
print(f"Encryption not supported: {e}")UnsupportedFileFormatException
Properties: from aspose.note import UnsupportedFileFormatException Properties: AsposeNoteError
当文件格式未被识别为有效的 .one 文件。公开一个 FileFormat 属性(字符串),包含检测到的或尝试的格式标识符。.
Properties
| Properties | Properties | Properties |
|---|---|---|
FileFormat | `str | None` |
抛出时
- 由
Document.__init__当解析器无法将文件识别为受支持的 OneNote 格式时。.
Properties
from aspose.note import Document, UnsupportedFileFormatException
try:
doc = Document("notatonenote.xlsx")
except UnsupportedFileFormatException as e:
print(f"Unsupported format: {e}")
if e.FileFormat:
print(f"Detected format: {e.FileFormat}")UnsupportedSaveFormatException
Properties: from aspose.note import UnsupportedSaveFormatException Properties: AsposeNoteError
在以下情况下抛出 Document.Save() 被调用时使用了一个 SaveFormat 或选项类在 v26.3.1 中未实现。仅 SaveFormat.Pdf 已实现;所有其他格式都会抛出此异常。.
抛出时
Document.Save(target, SaveFormat.One)— OneNote 循环往返格式已声明但未实现Document.Save(target, ...)使用任何SaveOptions子类且未PdfSaveOptions
Properties
from aspose.note import Document, SaveFormat, UnsupportedSaveFormatException
doc = Document("MyNotes.one")
try:
doc.Save("output.one", SaveFormat.One)
except UnsupportedSaveFormatException as e:
print(f"Save format not supported: {e}")捕获所有加载错误
from aspose.note import (
Document,
FileCorruptedException,
IncorrectDocumentStructureException,
IncorrectPasswordException,
UnsupportedFileFormatException,
)
def safe_load(path: str) -> Document | None:
try:
return Document(path)
except FileCorruptedException:
print(f"{path}: file is corrupted")
except IncorrectDocumentStructureException:
print(f"{path}: invalid document structure")
except IncorrectPasswordException:
print(f"{path}: encrypted documents are not supported")
except UnsupportedFileFormatException:
print(f"{path}: format not recognized")
return None捕获所有保存错误
from aspose.note import (
Document, SaveFormat, UnsupportedSaveFormatException
)
doc = Document("MyNotes.one")
try:
doc.Save("output.pdf", SaveFormat.Pdf)
except UnsupportedSaveFormatException as e:
print(f"Cannot save: {e}")另见
- Properties::构造函数会抛出加载异常;;
Save()抛出UnsupportedSaveFormatException - LoadOptions::设置
DocumentPassword触发IncorrectPasswordException - SaveFormat::仅
SaveFormat.Pdf在 v26.3.1 中已实现