Exceptions

Exceptions — Aspose.Note FOSS for Python API Reference

Išimčių hierarchija

Visi išimtys gali būti importuojamos tiesiogiai iš aspose.note:

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

Paveldėjimo medis:

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

AsposeNoteError

ImageRenderOptions: from aspose.note import AsposeNoteError ImageRenderOptions: Exception

Bazinė klasė visoms Aspose.Note FOSS išimtim. Sugriebkite šią klasę, kad galėtumėte tvarkyti bet kokią bibliotekos klaidą, nepriklausomai nuo konkrečios priežasties.

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

Keliama, kai .one failas negali būti išanalizuotas, nes jo binarinė struktūra yra sugadinta arba neteisinga.

Kada iškeliamas

  • Iškeltas Document.__init__ kai failo analizatorius susiduria su neatkuriama dvejetainė klaida.

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

Iškeltas, kai failo struktūra atpažįstama kaip .one failas, tačiau turi neteisingą arba nepalaikomą vidinę struktūrą.

Kada iškeliamas

  • Keltas Document.__init__ kai failas praeina pagrindinius formato patikrinimus, bet turi struktūrinių problemų, kurios neleidžia įkelti.

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

Keltas, kai LoadOptions.DocumentPassword yra nustatyta. Užšifruoti (slaptažodžiu apsaugoti) dokumentai nėra palaikomi v26.3.1 versijoje.

Kada iškeliamas

  • Keltas Document.__init__ kai load_options.DocumentPassword nėra 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

Iškeliamas, kai failo formatas nėra atpažįstamas kaip galiojantis .one failas. Pateikia a FileFormat atributą (eilutę) su aptiktu arba bandomu formato identifikatoriumi.

ImageRenderOptions

ImageRenderOptionsImageRenderOptionsImageRenderOptions
FileFormat`strNone`

Kada iškeliamas

  • Keliama Document.__init__ kai parseris negali atpažinti failo kaip palaikomo OneNote formato.

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

Keliama, kai Document.Save() kviečiamas su SaveFormat arba parinkčių klasė, kuri nėra įgyvendinta v26.3.1. Tik SaveFormat.Pdf yra įgyvendinta; visi kiti formatai sukelia šią išimtį.

Kada iškeliamas

  • Document.Save(target, SaveFormat.One) — OneNote round‑trip formatas yra deklaruotas, bet neįgyvendintas
  • Document.Save(target, ...) naudojant bet kokį SaveOptions pakaitinė klasė, kuri nėra 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}")

Visų įkėlimo klaidų gaudymas

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

Visų įrašymo klaidų gaudymas

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

Žr. taip pat

  • ImageRenderOptions: konstruktorius iškelia įkėlimo išimtis; Save() kelia UnsupportedSaveFormatException
  • LoadOptions: nustatymas DocumentPassword paleidžia IncorrectPasswordException
  • SaveFormat: tik SaveFormat.Pdf yra įgyvendinta v26.3.1
 Lietuvių