Exceptions — Aspose.Note FOSS for Python API Reference

Undtagelseshierarki

Alle undtagelser kan importeres direkte fra aspose.note:

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

Arvstræ:

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

AsposeNoteError

Example: from aspose.note import AsposeNoteError Example: Exception

Basisklasse for alle Aspose.Note FOSS-undtagelser. Fang denne klasse for at håndtere enhver biblioteksfejl uanset den specifikke årsag.

from aspose.note import Document, AsposeNoteError

try:
    doc = Document("unknown.one")
except AsposeNoteError as e:
    print(f"Aspose.Note error: {e}")

FileCorruptedException

Example: from aspose.note import FileCorruptedException Example: AsposeNoteError

Kastes når den .one filen kan ikke parses, fordi dens binære struktur er korrupt eller fejlbehæftet.

Når den udløses

  • Kastes af Document.__init__ når filparseren støder på en uoprettelig binær fejl.

Example

from aspose.note import Document, FileCorruptedException

try:
    doc = Document("corrupted.one")
except FileCorruptedException as e:
    print(f"File is corrupted: {e}")

IncorrectDocumentStructureException

Example: from aspose.note import IncorrectDocumentStructureException Example: AsposeNoteError

Kastes når filstrukturen genkendes som en .one fil, men indeholder en ugyldig eller ikke‑understøttet intern struktur.

Når den udløses

  • Kastes af Document.__init__ når filen bestå de grundlæggende formatkontroller, men har strukturelle problemer, der forhindrer indlæsning.

Example

from aspose.note import Document, IncorrectDocumentStructureException

try:
    doc = Document("unusual.one")
except IncorrectDocumentStructureException as e:
    print(f"Document structure error: {e}")

IncorrectPasswordException

Example: from aspose.note import IncorrectPasswordException Example: AsposeNoteError

Kastes når LoadOptions.DocumentPassword er indstillet. Krypterede (adgangskodebeskyttede) dokumenter understøttes ikke i v26.3.1.

Når den udløses

  • Kastes af Document.__init__ når load_options.DocumentPassword er ikke None.

Example

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

Example: from aspose.note import UnsupportedFileFormatException Example: AsposeNoteError

Kastes når filformatet ikke genkendes som en gyldig .one fil. Eksponerer en FileFormat attribut (en streng) med den registrerede eller forsøgte formatidentifikator.

Example

ExampleExampleExample
FileFormat`strNone`

Når den udløses

  • Udløst af Document.__init__ når parseren ikke kan identificere filen som et understøttet OneNote-format.

Example

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

Example: from aspose.note import UnsupportedSaveFormatException Example: AsposeNoteError

Kastes når Document.Save() kaldes med en SaveFormat eller options‑klasse, der ikke er implementeret i v26.3.1. Kun SaveFormat.Pdf er implementeret; alle andre formater kaster denne undtagelse.

Når den udløses

  • Document.Save(target, SaveFormat.One) — OneNote round‑trip-format er erklæret, men ikke implementeret
  • Document.Save(target, ...) ved brug af enhver SaveOptions underklasse, der ikke er PdfSaveOptions

Example

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

Fangning af alle indlæsningsfejl

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

Fangning af alle gemmefejl

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

Se også

  • Example: konstruktøren kaster indlæsnings‑undtagelser; Save() kaster UnsupportedSaveFormatException
  • LoadOptions: indstilling DocumentPassword udløser IncorrectPasswordException
  • SaveFormat: kun SaveFormat.Pdf er implementeret i v26.3.1
 Dansk