Exceptions — Aspose.Note FOSS for Python API Reference
Hijerarhija iznimaka
Sve iznimke se mogu izravno uvesti iz aspose.note:
from aspose.note import (
AsposeNoteError,
FileCorruptedException,
IncorrectDocumentStructureException,
IncorrectPasswordException,
UnsupportedFileFormatException,
UnsupportedSaveFormatException,
)Stablo nasljeđivanja:
Exception
└── AsposeNoteError
├── FileCorruptedException
├── IncorrectDocumentStructureException
├── IncorrectPasswordException
├── UnsupportedFileFormatException
└── UnsupportedSaveFormatExceptionAsposeNoteError
: from aspose.note import AsposeNoteError : Exception
Osnovna klasa za sve Aspose.Note FOSS iznimke. Uhvatite ovu klasu kako biste obradili bilo koju grešku biblioteke neovisno o specifičnom uzroku.
from aspose.note import Document, AsposeNoteError
try:
doc = Document("unknown.one")
except AsposeNoteError as e:
print(f"Aspose.Note error: {e}")FileCorruptedException
: from aspose.note import FileCorruptedException : AsposeNoteError
Biva podignuta kada .one datoteka se ne može parsirati jer je njezina binarna struktura oštećena ili nepravilna.
Kada se pokrene
- Podignuta od
Document.__init__kada parser datoteke naiđe na nepovratnu binarnu grešku.
from aspose.note import Document, FileCorruptedException
try:
doc = Document("corrupted.one")
except FileCorruptedException as e:
print(f"File is corrupted: {e}")IncorrectDocumentStructureException
: from aspose.note import IncorrectDocumentStructureException : AsposeNoteError
Pokreće se kada je struktura datoteke prepoznata kao .one datoteka, ali sadrži neispravnu ili nepodržanu internu strukturu.
Kada se pokrene
- Pokreće
Document.__init__kada datoteka prođe osnovne provjere formata, ali ima strukturalne probleme koji sprječavaju učitavanje.
from aspose.note import Document, IncorrectDocumentStructureException
try:
doc = Document("unusual.one")
except IncorrectDocumentStructureException as e:
print(f"Document structure error: {e}")IncorrectPasswordException
: from aspose.note import IncorrectPasswordException : AsposeNoteError
Pokreće se kada LoadOptions.DocumentPassword je postavljeno. Šifrirani (zaštićeni lozinkom) dokumenti nisu podržani u v26.3.1.
Kada se pokrene
- Pokreće
Document.__init__kadaload_options.DocumentPasswordnijeNone.
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
: from aspose.note import UnsupportedFileFormatException : AsposeNoteError
Pokreće se kada format datoteke nije prepoznat kao valjani .one datoteka. Izlaže a FileFormat atribut (string) s otkrivenim ili pokušanim identifikatorom formata.
FileFormat | `str | None` |
Kada se pokrene
- Pokreće
Document.__init__kada parser ne može prepoznati datoteku kao podržani OneNote format.
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
: from aspose.note import UnsupportedSaveFormatException : AsposeNoteError
Pokreće se kada Document.Save() se poziva s SaveFormat ili klasa opcija koja nije implementirana u v26.3.1. Samo SaveFormat.Pdf je implementiran; svi ostali formati izazivaju ovaj izuzetak.
Kada se pokrene
Document.Save(target, SaveFormat.One)— OneNote round‑trip format je deklariran, ali nije implementiranDocument.Save(target, ...)koristeći bilo kojiSaveOptionspodklasu koja nijePdfSaveOptions
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}")Hvatanje svih grešaka pri učitavanju
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 NoneHvatanje svih grešaka pri spremanju
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}")Vidi također
- : konstruktor izaziva iznimke pri učitavanju;
Save()izazivaUnsupportedSaveFormatException - LoadOptions: postavljanje
DocumentPasswordpokrećeIncorrectPasswordException - SaveFormat: samo
SaveFormat.Pdfje implementiran u v26.3.1