Exceptions

Exceptions — Aspose.Note FOSS for Python API Reference

例外階層

すべての例外は直接インポートできます aspose.note:

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

継承ツリー:

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

AsposeNoteError

ImageRenderOptions: from aspose.note import AsposeNoteError ImageRenderOptions: Exception

すべての Aspose.Note FOSS 例外の基底クラスです。このクラスを捕捉することで、特定の原因に関係なくライブラリのエラー全般を処理できます。.

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

次の場合に発生します .one ファイルは、バイナリ構造が破損または不正な形式であるため、解析できません。.

発生したとき

  • 次によって発生します Document.__init__ ファイルパーサが回復不能なバイナリエラーに遭遇したとき.

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

ファイル構造が〜として認識されたときに発生します .one ファイルですが、無効またはサポートされていない内部構造が含まれています。.

発生したとき

  • 次によって発生します Document.__init__ ファイルが基本的なフォーマットチェックを通過したものの、ロードを妨げる構造上の問題がある場合に発生します.

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

発生したとき LoadOptions.DocumentPassword が設定されている場合。暗号化(パスワード保護)されたドキュメントは v26.3.1 ではサポートされていません。.

発生したとき

  • 発生元 Document.__init__load_options.DocumentPassword ではない 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

ファイル形式が有効なものとして認識されない場合に発生 .one ファイル。属性を公開 FileFormat 属性(文字列)で、検出されたまたは試行された形式識別子を保持します。.

ImageRenderOptions

ImageRenderOptionsImageRenderOptionsImageRenderOptions
FileFormat`strNone`

発生したとき

  • 発生元 Document.__init__ パーサーがファイルをサポートされている OneNote 形式として識別できない場合。.

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

次の場合に発生 Document.Save() が呼び出されたとき、 SaveFormat または v26.3.1 で実装されていないオプション クラスです。Only SaveFormat.Pdf が実装されています;他のすべての形式はこの例外をスローします。.

発生したとき

  • Document.Save(target, SaveFormat.One) — OneNote ラウンドトリップ形式は宣言されていますが、実装されていません
  • Document.Save(target, ...) 任意の SaveOptions 実装されていないサブクラス 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}")

すべてのロードエラーを捕捉

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

すべての保存エラーを捕捉

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

関連項目

  • ImageRenderOptions: コンストラクタはロード例外を発生させます; Save() 発生させます UnsupportedSaveFormatException
  • LoadOptions: 設定 DocumentPassword トリガーします IncorrectPasswordException
  • SaveFormat: のみ SaveFormat.Pdf v26.3.1で実装されています
 日本語