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
    └── UnsupportedSaveFormatException

AsposeNoteError

: 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__ kada load_options.DocumentPassword nije None.

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`strNone`

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 implementiran
  • Document.Save(target, ...) koristeći bilo koji SaveOptions podklasu koja nije PdfSaveOptions

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 None

Hvatanje 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() izaziva UnsupportedSaveFormatException
  • LoadOptions: postavljanje DocumentPassword pokreće IncorrectPasswordException
  • SaveFormat: samo SaveFormat.Pdf je implementiran u v26.3.1
 Hrvatski