Exceptions — Aspose.Note FOSS for Python API Reference

Zachycení všech chyb ukládání

Všechny výjimky lze importovat přímo z aspose.note:

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

API reference pro všechny výjimky v aspose-note v26.3.1 — AsposeNoteError, FileCorruptedException, IncorrectDocumentStructureException, IncorrectPasswordException, UnsupportedFileFormatException, and UnsupportedSaveFormatException.:

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

AsposeNoteError

Example: from aspose.note import AsposeNoteError Example: Exception

Vyvolána metodou Document.__init__, když parser souboru narazí na neodstranitelnou binární chybu.

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

Vyvoláno, když .one soubor nelze analyzovat, protože jeho binární struktura je poškozena nebo nesprávně formátována.

Import: from aspose.note import FileCorruptedException Dědí: AsposeNoteError

  • Vyvoláno v Document.__init__ když parser souboru narazí na neodstranitelnou binární chybu.

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

Vyvoláno, když je struktura souboru rozpoznána jako .one soubor, ale obsahuje neplatnou nebo nepodporovanou vnitřní strukturu.

Import: from aspose.note import FileCorruptedException Dědí: AsposeNoteError

  • Vyvoláno Document.__init__ když soubor projde základními kontrolami formátu, ale má strukturální problémy, které brání načtení.

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

Vyvoláno, když LoadOptions.DocumentPassword je nastaveno. Šifrované (chráněné heslem) dokumenty nejsou podporovány ve verzi 26.3.1.

Import: from aspose.note import FileCorruptedException Dědí: AsposeNoteError

  • Vyvoláno Document.__init__ když load_options.DocumentPassword není 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

Vyvoláno, když formát souboru není rozpoznán jako platný .one soubor. Zveřejňuje FileFormat atribut (řetězec) s detekovaným nebo pokusným identifikátorem formátu.

Example

ExampleExampleExample
FileFormat`strNone`

Import: from aspose.note import FileCorruptedException Dědí: AsposeNoteError

  • Vyvoláno Document.__init__ když parser nedokáže identifikovat soubor jako podporovaný formát OneNote.

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

Vyvoláno, když Document.Save() je voláno s SaveFormat nebo třída možností, která není implementována ve verzi v26.3.1. Pouze SaveFormat.Pdf je implementována; všechny ostatní formáty vyvolají tuto výjimku.

Import: from aspose.note import FileCorruptedException Dědí: AsposeNoteError

  • Document.Save(target, SaveFormat.One) — Formát OneNote round-trip je deklarován, ale není implementován
  • Document.Save(target, ...) při použití jakéhokoli SaveOptions podtřídy, která není 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}")

Zachytávání všech chyb načítání

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

Vyvoláno metodou Document.__init__, když load_options.DocumentPassword není None.

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

Viz také

  • Example: konstruktor vyvolává výjimky při načítání; Save() vyvolá UnsupportedSaveFormatException
  • LoadOptions: nastavení DocumentPassword spouští IncorrectPasswordException
  • SaveFormat: pouze SaveFormat.Pdf je implementováno ve verzi v26.3.1
 Čeština