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
└── UnsupportedSaveFormatExceptionAsposeNoteError
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.3.1.
When raised
- Raised by
Document.__init__whenload_options.DocumentPasswordis notNone.
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
| Attribute | Type | Description |
|---|---|---|
FileFormat | str | None | String 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.3.1. Only SaveFormat.Pdf is implemented; all other formats raise this exception.
When raised
Document.Save(target, SaveFormat.One)— OneNote round-trip format is declared but not implementedDocument.Save(target, ...)using anySaveOptionssubclass that is notPdfSaveOptions
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}")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 NoneCatching 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()raisesUnsupportedSaveFormatException - LoadOptions: setting
DocumentPasswordtriggersIncorrectPasswordException - SaveFormat: only
SaveFormat.Pdfis implemented in v26.3.1