Exceptions — Aspose.Note FOSS for Python API Reference

Ierarhia excepțiilor

Toate excepțiile pot fi importate direct din aspose.note:

from aspose.note import (
    AsposeNoteError,
    FileCorruptedException,
    IncorrectDocumentStructureException,
    IncorrectPasswordException,
    UnsupportedFileFormatException,
    UnsupportedSaveFormatException,
)

Arbore de moștenire:

Exception
└── AsposeNoteError
    ├── FileCorruptedException
    ├── IncorrectDocumentStructureException
    ├── IncorrectPasswordException
    ├── UnsupportedFileFormatException
    └── UnsupportedSaveFormatException

AsposeNoteError

ImageRenderOptions: from aspose.note import AsposeNoteError ImageRenderOptions: Exception

Clasa de bază pentru toate excepțiile Aspose.Note FOSS. Prindeți această clasă pentru a gestiona orice eroare a bibliotecii, indiferent de cauza specifică.

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

Ridicată când .one fișierul nu poate fi analizat deoarece structura sa binară este coruptă sau malformată.

Când este ridicată

  • Ridicată de Document.__init__ când parserul de fișiere întâlnește o eroare binară irecuperabilă.

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

Ridicată când structura fișierului este recunoscută ca un .one fișier, dar conține o structură internă invalidă sau nesuportată.

Când este ridicată

  • Ridicată de Document.__init__ când fișierul trece verificările de bază ale formatului, dar are probleme structurale care împiedică încărcarea.

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

Ridicată când LoadOptions.DocumentPassword este setat. Documentele criptate (protejate prin parolă) nu sunt suportate în v26.3.1.

Când este ridicată

  • Generat de Document.__init__ când load_options.DocumentPassword nu este 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

Generat când formatul fișierului nu este recunoscut ca un valid .one fișier. Expune un FileFormat atribut (un șir) cu identificatorul de format detectat sau încercat.

ImageRenderOptions

ImageRenderOptionsImageRenderOptionsImageRenderOptions
FileFormat`strNone`

Când este ridicată

  • Generat de Document.__init__ când parserul nu poate identifica fișierul ca un format OneNote suportat.

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

Generat când Document.Save() este apelat cu un SaveFormat sau clasa de opțiuni care nu este implementată în v26.3.1. Doar SaveFormat.Pdf este implementată; toate celelalte formate generează această excepție.

Când este ridicată

  • Document.Save(target, SaveFormat.One) — Formatul OneNote round-trip este declarat, dar nu este implementat
  • Document.Save(target, ...) folosind orice SaveOptions subclasă care nu este 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}")

Capturarea tuturor erorilor de încărcare

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

Capturarea tuturor erorilor de salvare

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}")

Vezi și

  • ImageRenderOptions: constructorul generează excepții la încărcare; Save() generează UnsupportedSaveFormatException
  • LoadOptions: setarea DocumentPassword declanșează IncorrectPasswordException
  • SaveFormat: doar SaveFormat.Pdf este implementată în v26.3.1
 Română