Exceptions

Exceptions — Aspose.Note FOSS for Python API Reference

Hierarchia výnimiek

Všetky výnimky je možné importovať priamo z aspose.note:

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

Strom dedičnosti:

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

AsposeNoteError

ImageRenderOptions: from aspose.note import AsposeNoteError ImageRenderOptions: Exception

Základná trieda pre všetky Aspose.Note FOSS výnimky. Zachyťte túto triedu, aby ste spracovali akúkoľvek chybu knižnice bez ohľadu na konkrétnu príčinu.

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

Vyvolaná, keď the .one súbor nie je možné analyzovať, pretože jeho binárna štruktúra je poškodená alebo nesprávna.

Keď sa vyvolá

  • Vyvolaná Document.__init__ keď parser súboru narazí na neodstrániteľnú binárnu chybu.

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

Vyvolaná, keď je štruktúra súboru rozpoznaná ako .one súbor, ale obsahuje neplatnú alebo nepodporovanú vnútornú štruktúru.

Keď sa vyvolá

  • Vyvolaná Document.__init__ keď súbor prejde základnými kontrolami formátu, ale má štrukturálne problémy, ktoré zabraňujú načítaniu.

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

Vyvolaná, keď LoadOptions.DocumentPassword je nastavené. Šifrované (chránené heslom) dokumenty nie sú podporované vo verzii v26.3.1.

Keď sa vyvolá

  • Vyvolaná Document.__init__ keď load_options.DocumentPassword nie je 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

Vyvolaná, keď formát súboru nie je rozpoznaný ako platný .one súbor. Zverejňuje a FileFormat atribút (reťazec) s detekovaným alebo pokúšaným identifikátorom formátu.

ImageRenderOptions

ImageRenderOptionsImageRenderOptionsImageRenderOptions
FileFormat`strNone`

Keď sa vyvolá

  • Vyvolané v Document.__init__ keď parser nedokáže identifikovať súbor ako podporovaný formát OneNote.

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

Vyvolané, keď Document.Save() sa volá s SaveFormat alebo triedou možností, ktorá nie je implementovaná vo verzii v26.3.1. Iba SaveFormat.Pdf je implementovaný; všetky ostatné formáty vyvolajú túto výnimku.

Keď sa vyvolá

  • Document.Save(target, SaveFormat.One) — Formát OneNote round-trip je deklarovaný, ale nie je implementovaný
  • Document.Save(target, ...) používajúc akýkoľvek SaveOptions podtriedu, ktorá nie je 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}")

Zachytávanie všetkých chýb načítania

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

Zachytávanie všetkých chýb ukladania

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

Pozri tiež

  • ImageRenderOptions: konštruktor vyvoláva výnimky pri načítaní; Save() vyvoláva UnsupportedSaveFormatException
  • LoadOptions: nastavenie DocumentPassword spúšťa IncorrectPasswordException
  • SaveFormat: iba SaveFormat.Pdf je implementovaný vo verzii v26.3.1
 Slovenčina