Exceptions

Exceptions — Aspose.Note FOSS for Python API Reference

Hijerarhija izuzetaka

Svi izuzeci se mogu uvesti direktno iz aspose.note:

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

Stablo nasleđivanja:

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

AsposeNoteError

: from aspose.note import AsposeNoteError
: Exception

Osnovna klasa za sve Aspose.Note FOSS izuzetke. Uhvatite ovu klasu da biste obradili bilo koju grešku biblioteke, bez obzira na konkretan uzrok.

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

Podignuto kada the .one datoteka ne može biti parsirana jer je njena binarna struktura oštećena ili nepravilna.

Kada se podigne

  • Podignuto 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

Podignuto kada se struktura datoteke prepozna kao .one datoteka, ali sadrži nevažeću ili nepodržanu internu strukturu.

Kada se podigne

  • Podignuto od Document.__init__ kada fajl prođe osnovne provere formata, ali ima strukturne probleme koji spreč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

Pokrenuto kada LoadOptions.DocumentPassword je postavljeno. Enkriptovani (zaštićeni lozinkom) dokumenti nisu podržani u v26.3.1.

Kada se podigne

  • Pokrenuto od 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

Pokrenuto kada format fajla nije prepoznat kao validan .one fajl. Izlaže a FileFormat atribut (string) sa detektovanim ili pokušanim identifikatorom formata.

FileFormat`strNone`

Kada se podigne

  • Podignuto od Document.__init__ kada parser ne može da identifikuje fajl 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

Podignuto kada Document.Save() se pozove sa SaveFormat ili klasa opcija koja nije implementirana u v26.3.1. Samo SaveFormat.Pdf je implementiran; svi ostali formati podižu ovaj izuzetak.

Kada se podigne

  • Document.Save(target, SaveFormat.One) — OneNote format za povratni tok je deklarisan, ali nije implementiran
  • Document.Save(target, ...) koristeći bilo koji SaveOptions podklasa 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 čuvanju

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 i

  • : konstruktor podiže izuzetke pri učitavanju; Save() podiže UnsupportedSaveFormatException
  • LoadOptions: postavka DocumentPassword okida IncorrectPasswordException
  • SaveFormat: samo SaveFormat.Pdf je implementirano u v26.3.1
 Српски