Exceptions — Aspose.Note FOSS for Python API Reference

Exception Hierarchy

All exceptions are importable directly from aspose.note:

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

Inheritance tree:

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

AsposeNoteError

Import: from aspose.note import AsposeNoteError Inherits: Exception

Base class for all Aspose.Note FOSS exceptions. Catch this class to handle any library error regardless of specific cause.

from aspose.note import Document, AsposeNoteError

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

FileCorruptedException

Import: from aspose.note import FileCorruptedException Inherits: AsposeNoteError

Raised when the .one file cannot be parsed because its binary structure is corrupted or malformed.

When raised

  • Raised by Document.__init__ when the file parser encounters an unrecoverable binary error.

Example

from aspose.note import Document, FileCorruptedException

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

IncorrectDocumentStructureException

Import: from aspose.note import IncorrectDocumentStructureException Inherits: AsposeNoteError

Raised when the file structure is recognized as a .one file but contains an invalid or unsupported internal structure.

When raised

  • Raised by Document.__init__ when the file passes basic format checks but has structural problems that prevent loading.

Example

from aspose.note import Document, IncorrectDocumentStructureException

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

IncorrectPasswordException

Import: from aspose.note import IncorrectPasswordException Inherits: AsposeNoteError

Raised when LoadOptions.DocumentPassword is set. Encrypted (password-protected) documents are not supported in v26.2.

When raised

  • Raised by Document.__init__ when load_options.DocumentPassword is not 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

Import: from aspose.note import UnsupportedFileFormatException Inherits: AsposeNoteError

Raised when the file format is not recognized as a valid .one file. Exposes a FileFormat attribute (a string) with the detected or attempted format identifier.

Attributes

AttributeTypeDescription
FileFormatstr | NoneString identifier of the format that was attempted, or None

When raised

  • Raised by Document.__init__ when the parser cannot identify the file as a supported 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

Import: from aspose.note import UnsupportedSaveFormatException Inherits: AsposeNoteError

Raised when Document.Save() is called with a SaveFormat or options class that is not implemented in v26.2. Only SaveFormat.Pdf is implemented; all other formats raise this exception.

When raised

  • Document.Save(target, SaveFormat.One) — OneNote format not implemented
  • Document.Save(target, SaveFormat.Html) — HTML not implemented
  • Document.Save(target, SaveFormat.Jpeg) — raster export not implemented
  • Document.Save(target, OneSaveOptions(...)) — OneSaveOptions not implemented
  • Document.Save(target, HtmlSaveOptions(...)) — HtmlSaveOptions not implemented
  • Document.Save(target, ImageSaveOptions(...)) — ImageSaveOptions not implemented
  • Document.Save(target, ...) on a Document that was created empty (Document()) and then asked for PDF — cannot export an empty document

Example

from aspose.note import Document, SaveFormat, UnsupportedSaveFormatException

doc = Document("MyNotes.one")

try:
    doc.Save("output.html", SaveFormat.Html)
except UnsupportedSaveFormatException as e:
    print(f"Save format not supported: {e}")

Catching All Load Errors

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

Catching All Save Errors

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

See Also

  • Document: constructor raises load exceptions; Save() raises UnsupportedSaveFormatException
  • LoadOptions: setting DocumentPassword triggers IncorrectPasswordException
  • SaveFormat: only SaveFormat.Pdf is implemented in v26.2