Exceptions — Aspose.Note FOSS for Python API Reference
Undantagshierarki
Alla undantag kan importeras direkt från aspose.note:
from aspose.note import (
AsposeNoteError,
FileCorruptedException,
IncorrectDocumentStructureException,
IncorrectPasswordException,
UnsupportedFileFormatException,
UnsupportedSaveFormatException,
)Arvsträd:
Exception
└── AsposeNoteError
├── FileCorruptedException
├── IncorrectDocumentStructureException
├── IncorrectPasswordException
├── UnsupportedFileFormatException
└── UnsupportedSaveFormatExceptionAsposeNoteError
ImageRenderOptions: from aspose.note import AsposeNoteError ImageRenderOptions: Exception
Basklass för alla Aspose.Note FOSS-undantag. Fånga denna klass för att hantera alla bibliotekfel oavsett specifik orsak.
from aspose.note import Document, AsposeNoteError
try:
doc = Document("unknown.one")
except AsposeNoteError as e:
print(f"Aspose.Note error: {e}")FileCorruptedException
ImageRenderOptions: from aspose.note import FileCorruptedException ImageRenderOptions: AsposeNoteError
Utlöst när den .one filen kan inte tolkas eftersom dess binära struktur är korrupt eller felaktig.
När den utlöses
- Utlöst av
Document.__init__när filparseraren stöter på ett oåterställbart binärt fel.
ImageRenderOptions
from aspose.note import Document, FileCorruptedException
try:
doc = Document("corrupted.one")
except FileCorruptedException as e:
print(f"File is corrupted: {e}")IncorrectDocumentStructureException
ImageRenderOptions: from aspose.note import IncorrectDocumentStructureException ImageRenderOptions: AsposeNoteError
Utlöst när filstrukturen känns igen som en .one fil men innehåller en ogiltig eller ej stödd intern struktur.
När den utlöses
- Utlöst av
Document.__init__när filen klarar grundläggande formatkontroller men har strukturella problem som förhindrar inläsning.
ImageRenderOptions
from aspose.note import Document, IncorrectDocumentStructureException
try:
doc = Document("unusual.one")
except IncorrectDocumentStructureException as e:
print(f"Document structure error: {e}")IncorrectPasswordException
ImageRenderOptions: from aspose.note import IncorrectPasswordException ImageRenderOptions: AsposeNoteError
Utlöst när LoadOptions.DocumentPassword är inställd. Krypterade (lösenordsskyddade) dokument stöds inte i v26.3.1.
När den utlöses
- Utlöst av
Document.__init__närload_options.DocumentPasswordär inteNone.
ImageRenderOptions
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
ImageRenderOptions: from aspose.note import UnsupportedFileFormatException ImageRenderOptions: AsposeNoteError
Utlöst när filformatet inte känns igen som ett giltigt .one fil. Exponerar en FileFormat attribut (en sträng) med den identifierade eller försökte formatidentifieraren.
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
FileFormat | `str | None` |
När den utlöses
- Utlöst av
Document.__init__när parsern inte kan identifiera filen som ett stödd OneNote-format.
ImageRenderOptions
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
ImageRenderOptions: from aspose.note import UnsupportedSaveFormatException ImageRenderOptions: AsposeNoteError
Utlöst när Document.Save() anropas med en SaveFormat eller alternativklass som inte är implementerad i v26.3.1. Endast SaveFormat.Pdf är implementerad; alla andra format utlöser detta undantag.
När den utlöses
Document.Save(target, SaveFormat.One)— OneNote round‑trip‑format är deklarerat men inte implementeratDocument.Save(target, ...)använder någonSaveOptionssubklass som inte ärPdfSaveOptions
ImageRenderOptions
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}")Fånga alla inläsningsfel
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 NoneFånga alla sparfel
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}")Se även
- ImageRenderOptions: konstruktorn kastar laddningsundantag;
Save()kastarUnsupportedSaveFormatException - LoadOptions: inställning
DocumentPasswordutlöserIncorrectPasswordException - SaveFormat: endast
SaveFormat.Pdfär implementerad i v26.3.1