如何在丢失字体文件时捕获异常?
我的代码正在关注
public static final String FONT_RU = "arialuni.ttf";
public static final String FONT_CH = "hxb-meixinti.ttf";
BaseFont bf_ru = BaseFont.createFont(FONT_RU,BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
当缺少字体文件(例如hxb-meixinti.ttf)时如何捕获异常?
答案 0 :(得分:0)
createFont方法可以抛出两个例外:
DocumentException - >字体无效时抛出
IOException - >无法读取字体时抛出
try {
BaseFont bf_ru =BaseFont.createFont(FONT_RU,BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
}
catch (DocumentException e) {
//Font not found/invalid
}