Exceptions — Aspose.Note FOSS for Python API Reference
Gerarchia delle eccezioni
Tutte le eccezioni sono importabili direttamente da aspose.note:
from aspose.note import (
AsposeNoteError,
FileCorruptedException,
IncorrectDocumentStructureException,
IncorrectPasswordException,
UnsupportedFileFormatException,
UnsupportedSaveFormatException,
)Albero di ereditarietà:
Exception
└── AsposeNoteError
├── FileCorruptedException
├── IncorrectDocumentStructureException
├── IncorrectPasswordException
├── UnsupportedFileFormatException
└── UnsupportedSaveFormatExceptionAsposeNoteError
ImageRenderOptions: from aspose.note import AsposeNoteError ImageRenderOptions: Exception
Classe base per tutte le eccezioni FOSS Aspose.Note. Cattura questa classe per gestire qualsiasi errore della libreria indipendentemente dalla causa specifica.
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
Generata quando il .one il file non può essere analizzato perché la sua struttura binaria è corrotta o malformata.
Quando viene generato
- Generata da
Document.__init__quando il parser del file incontra un errore binario irrecuperabile.
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
Generata quando la struttura del file è riconosciuta come una .one file ma contiene una struttura interna non valida o non supportata.
Quando viene generato
- Generata da
Document.__init__quando il file supera i controlli di formato di base ma presenta problemi strutturali che impediscono il caricamento.
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
Generata quando LoadOptions.DocumentPassword è impostato. I documenti crittografati (protetti da password) non sono supportati in v26.3.1.
Quando viene generato
- Generata da
Document.__init__quandoload_options.DocumentPasswordnon èNone.
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
Generata quando il formato del file non è riconosciuto come un valido .one file. Espone un FileFormat attributo (una stringa) con l’identificatore di formato rilevato o tentato.
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
FileFormat | `str | None` |
Quando viene generato
- Generato da
Document.__init__quando il parser non riesce a identificare il file come un formato OneNote supportato.
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
Generato quando Document.Save() viene chiamato con un SaveFormat o classe di opzioni che non è implementata in v26.3.1. Solo SaveFormat.Pdf è implementato; tutti gli altri formati generano questa eccezione.
Quando viene generato
Document.Save(target, SaveFormat.One)— Il formato round-trip OneNote è dichiarato ma non implementatoDocument.Save(target, ...)utilizzando qualsiasiSaveOptionssottoclasse che non èPdfSaveOptions
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}")Catturare tutti gli errori di caricamento
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 NoneCatturare tutti gli errori di salvataggio
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}")Vedi anche
- ImageRenderOptions: il costruttore genera eccezioni di caricamento;
Save()generaUnsupportedSaveFormatException - LoadOptions: impostazione
DocumentPasswordtriggersIncorrectPasswordException - SaveFormat: solo
SaveFormat.Pdfè implementato in v26.3.1