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
Enumerations: from aspose.note import AsposeNoteError Enumerations: 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
Enumerations: from aspose.note import FileCorruptedException Enumerations: AsposeNoteError
Викидається, коли .one файл не може бути розпарсений, оскільки його бінарна структура пошкоджена або некоректна.
Коли викидається
- Викидається
Document.__init__коли парсер файлу стикається з невідновлюваною бінарною помилкою.
Enumerations
from aspose.note import Document, FileCorruptedException
try:
doc = Document("corrupted.one")
except FileCorruptedException as e:
print(f"File is corrupted: {e}")IncorrectDocumentStructureException
Enumerations: from aspose.note import IncorrectDocumentStructureException Enumerations: AsposeNoteError
Викидається, коли структура файлу розпізнається як .one файл, але містить недійсну або непідтримувану внутрішню структуру.
Коли викидається
- Викидається
Document.__init__коли файл проходить базові перевірки формату, але має структурні проблеми, які перешкоджають завантаженню.
Enumerations
from aspose.note import Document, IncorrectDocumentStructureException
try:
doc = Document("unusual.one")
except IncorrectDocumentStructureException as e:
print(f"Document structure error: {e}")IncorrectPasswordException
Enumerations: from aspose.note import IncorrectPasswordException Enumerations: AsposeNoteError
Викликається, коли LoadOptions.DocumentPassword встановлено. Шифровані (захищені паролем) документи не підтримуються у v26.3.1.
Коли викидається
- Викликається
Document.__init__колиload_options.DocumentPasswordне єNone.
Enumerations
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
Enumerations: from aspose.note import UnsupportedFileFormatException Enumerations: AsposeNoteError
Викликається, коли формат файлу не розпізнається як дійсний .one файл. Розкриває a FileFormat атрибут (рядок) з виявленим або спробованим ідентифікатором формату.
Enumerations
| Enumerations | Enumerations | Enumerations |
|---|---|---|
FileFormat | `str | None` |
Коли викидається
- Викидається в
Document.__init__коли парсер не може ідентифікувати файл як підтримуваний формат OneNote.
Enumerations
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
Enumerations: from aspose.note import UnsupportedSaveFormatException Enumerations: AsposeNoteError
Викидається, коли Document.Save() викликається з SaveFormat або класом параметрів, який не реалізовано у v26.3.1. Тільки SaveFormat.Pdf реалізовано; усі інші формати викликають цей виняток.
Коли викидається
Document.Save(target, SaveFormat.One)— Формат кругового проходу OneNote оголошено, але не реалізованоDocument.Save(target, ...)використовуючи anySaveOptionsпідклас, який неPdfSaveOptions
Enumerations
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}")Див. також
- Enumerations: конструктор піднімає виключення завантаження;
Save()піднімаєUnsupportedSaveFormatException - LoadOptions: налаштування
DocumentPasswordвикликаєIncorrectPasswordException - SaveFormat: лише
SaveFormat.Pdfреалізовано у v26.3.1