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 پیاده‌سازی نشده است. فقط SaveFormat.Pdf پیاده‌سازی شده است؛ تمام فرمت‌های دیگر این استثنا را پرتاب می‌کنند.

زمانی که رخ می‌دهد

  • Document.Save(target, SaveFormat.One) — فرمت round-trip 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 پیاده‌سازی شده است
 فارسی