导出和加载期间的回调错误
Contents
[
Hide
]导出和加载期间回调错误的回顾
在导出或加载图纸时,我们可能会遇到与文件结构相关的错误 (例如,文件中的某些部分现在是必需的,但之前不是)。 其中一些是关键错误,在这种情况下会抛出异常,但我们也可以内部忽略其中一些,并使用回调消息通知。 无论如何,所有这些消息都需要关注,因为它们可能会解释例如导出结果中缺失的实体或其他效果。
导出期间的错误
在 CadRasterizationOptions 中有一个 RenderResult 字段, 它包含 IsRenderComplete 用于获取导出期间是否发生错误并打印相关信息:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var image = Aspose.CAD.Image.Load(fileName)) | |
{ | |
image.Save(outfile, new PdfOptions() | |
{ | |
VectorRasterizationOptions = new CadRasterizationOptions() | |
{ | |
RenderResult = result => | |
{ | |
if (!result.IsRenderComplete) | |
{ | |
foreach (var resultFailure in result.Failures) | |
{ | |
System.Console.WriteLine($"Error: {resultFailure.Message} (error code {resultFailure.RenderCode})"); | |
} | |
} | |
} | |
} | |
}); | |
} |
加载期间的错误
在导出过程开始之前,可能会观察到图纸的一些问题。 LoadOptions 对象中的 Errors 属性用于存储有关它们的消息。 IgnoreErrors 属性对于决定是否 在加载错误时抛出异常非常有用。
这是 Errors 属性使用的示例:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LoadOptions options = new LoadOptions(); | |
using (Image cadImage = Image.Load(fileName, options)) | |
{ | |
foreach (RenderResult renderResult in options.Errors) | |
{ | |
System.Console.WriteLine(renderResult.RenderCode + " " + renderResult.Message); | |
} | |
... | |
} |