Processing, catch
用法介紹。
用法
try {
tryStatements
} catch (exception) {
catchStatements
}
參數
tryStatements
如果此代碼引發異常,則運行"catch" 中的代碼exception
拋出的 Java 異常catchStatements
處理異常的代碼
說明
catch
關鍵字與try
一起使用以處理異常。 Sun 的 Java 文檔將異常定義為“在程序執行期間發生的事件,它破壞了程序指令的正常流程”。例如,這可能是讀取文件時出錯。
例子
BufferedReader reader;
String line;
void setup() {
// Open the file from the createWriter() example
reader = createReader("positions.txt");
}
void draw() {
try {
line = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
line = null;
}
if (line == null) {
// Stop reading because of an error or file is empty
noLoop();
} else {
String[] pieces = split(line, TAB);
int x = int(pieces[0]);
int y = int(pieces[1]);
point(x, y);
}
}
相關用法
- Processing case用法及代碼示例
- Processing camera()用法及代碼示例
- Processing captureEvent()用法及代碼示例
- Processing clip()用法及代碼示例
- Processing curveDetail()用法及代碼示例
- Processing char()用法及代碼示例
- Processing ceil()用法及代碼示例
- Processing curveVertex()用法及代碼示例
- Processing concat()用法及代碼示例
- Processing continue用法及代碼示例
- Processing color()用法及代碼示例
- Processing copy()用法及代碼示例
- Processing createFont()用法及代碼示例
- Processing cos()用法及代碼示例
- Processing circle()用法及代碼示例
- Processing char用法及代碼示例
- Processing color用法及代碼示例
- Processing createImage()用法及代碼示例
- Processing createShape()用法及代碼示例
- Processing class用法及代碼示例
- Processing curve()用法及代碼示例
- Processing curveTightness()用法及代碼示例
- Processing createInput()用法及代碼示例
- Processing constrain()用法及代碼示例
- Processing clear()用法及代碼示例
注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 catch。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。