Exceptions

Exceptions — Aspose.Note FOSS for Python API Reference

Hierarchia wyjątków

Wszystkie wyjątki można importować bezpośrednio z aspose.note:

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

Drzewo dziedziczenia:

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

AsposeNoteError

ImageRenderOptions: from aspose.note import AsposeNoteError ImageRenderOptions: Exception

Klasa bazowa dla wszystkich wyjątków Aspose.Note FOSS. Przechwyć tę klasę, aby obsłużyć dowolny błąd biblioteki, niezależnie od konkretnej przyczyny.

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

Podnoszone, gdy .one plik nie może być analizowany, ponieważ jego struktura binarna jest uszkodzona lub nieprawidłowa.

Kiedy jest podnoszony

  • Zgłoszone przez Document.__init__ gdy parser pliku napotyka nieodwracalny błąd binarny.

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

Zgłaszany, gdy struktura pliku jest rozpoznana jako .one plik, ale zawiera nieprawidłową lub nieobsługiwaną wewnętrzną strukturę.

Kiedy jest podnoszony

  • Zgłaszany przez Document.__init__ gdy plik przechodzi podstawowe kontrole formatu, ale ma problemy strukturalne uniemożliwiające wczytanie.

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

Zgłaszany, gdy LoadOptions.DocumentPassword jest ustawione. Dokumenty zaszyfrowane (chronione hasłem) nie są obsługiwane w wersji v26.3.1.

Kiedy jest podnoszony

  • Zgłoszone przez Document.__init__ gdy load_options.DocumentPassword nie jest 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

Zgłoszone, gdy format pliku nie jest rozpoznany jako prawidłowy .one plik. Udostępnia FileFormat atrybut (ciąg znaków) z wykrytym lub próbowanym identyfikatorem formatu.

ImageRenderOptions

ImageRenderOptionsImageRenderOptionsImageRenderOptions
FileFormat`strNone`

Kiedy jest podnoszony

  • Rzucane przez Document.__init__ gdy parser nie może zidentyfikować pliku jako obsługiwanego formatu 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

Rzucane, gdy Document.Save() jest wywoływane z SaveFormat lub klasa opcji, która nie jest zaimplementowana w v26.3.1. Tylko SaveFormat.Pdf jest zaimplementowana; wszystkie inne formaty generują ten wyjątek.

Kiedy jest podnoszony

  • Document.Save(target, SaveFormat.One) — Format OneNote round-trip jest zadeklarowany, ale nie jest zaimplementowany
  • Document.Save(target, ...) używając dowolnego SaveOptions podklasy, która nie jest 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}")

Łapanie wszystkich błędów ładowania

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

Łapanie wszystkich błędów zapisu

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

Zobacz także

  • ImageRenderOptions: konstruktor generuje wyjątki ładowania; Save() generuje UnsupportedSaveFormatException
  • LoadOptions: ustawienie DocumentPassword wyzwala IncorrectPasswordException
  • SaveFormat: tylko SaveFormat.Pdf jest zaimplementowane w v26.3.1
 Polski