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) — פורמט OneNote round‑trip הוכרז אך לא ממומש
  • 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
 עברית