Exceptions — Aspose.Note FOSS for Python API Reference
Išimčių hierarchija
Visi išimtys gali būti importuojamos tiesiogiai iš aspose.note:
from aspose.note import (
AsposeNoteError,
FileCorruptedException,
IncorrectDocumentStructureException,
IncorrectPasswordException,
UnsupportedFileFormatException,
UnsupportedSaveFormatException,
)Paveldėjimo medis:
Exception
└── AsposeNoteError
├── FileCorruptedException
├── IncorrectDocumentStructureException
├── IncorrectPasswordException
├── UnsupportedFileFormatException
└── UnsupportedSaveFormatExceptionAsposeNoteError
ImageRenderOptions: from aspose.note import AsposeNoteError ImageRenderOptions: Exception
Bazinė klasė visoms Aspose.Note FOSS išimtim. Sugriebkite šią klasę, kad galėtumėte tvarkyti bet kokią bibliotekos klaidą, nepriklausomai nuo konkrečios priežasties.
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
Keliama, kai .one failas negali būti išanalizuotas, nes jo binarinė struktūra yra sugadinta arba neteisinga.
Kada iškeliamas
- Iškeltas
Document.__init__kai failo analizatorius susiduria su neatkuriama dvejetainė klaida.
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
Iškeltas, kai failo struktūra atpažįstama kaip .one failas, tačiau turi neteisingą arba nepalaikomą vidinę struktūrą.
Kada iškeliamas
- Keltas
Document.__init__kai failas praeina pagrindinius formato patikrinimus, bet turi struktūrinių problemų, kurios neleidžia įkelti.
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
Keltas, kai LoadOptions.DocumentPassword yra nustatyta. Užšifruoti (slaptažodžiu apsaugoti) dokumentai nėra palaikomi v26.3.1 versijoje.
Kada iškeliamas
- Keltas
Document.__init__kaiload_options.DocumentPasswordnėraNone.
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
Iškeliamas, kai failo formatas nėra atpažįstamas kaip galiojantis .one failas. Pateikia a FileFormat atributą (eilutę) su aptiktu arba bandomu formato identifikatoriumi.
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
FileFormat | `str | None` |
Kada iškeliamas
- Keliama
Document.__init__kai parseris negali atpažinti failo kaip palaikomo OneNote formato.
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
Keliama, kai Document.Save() kviečiamas su SaveFormat arba parinkčių klasė, kuri nėra įgyvendinta v26.3.1. Tik SaveFormat.Pdf yra įgyvendinta; visi kiti formatai sukelia šią išimtį.
Kada iškeliamas
Document.Save(target, SaveFormat.One)— OneNote round‑trip formatas yra deklaruotas, bet neįgyvendintasDocument.Save(target, ...)naudojant bet kokįSaveOptionspakaitinė klasė, kuri nėraPdfSaveOptions
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}")Visų įkėlimo klaidų gaudymas
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 NoneVisų įrašymo klaidų gaudymas
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}")Žr. taip pat
- ImageRenderOptions: konstruktorius iškelia įkėlimo išimtis;
Save()keliaUnsupportedSaveFormatException - LoadOptions: nustatymas
DocumentPasswordpaleidžiaIncorrectPasswordException - SaveFormat: tik
SaveFormat.Pdfyra įgyvendinta v26.3.1