Professional Documents
Culture Documents
Assignment 1
Assignment 1
FileNotFoundException. ...
IOException. ...
InterruptedException. ...
NoSuchFieldException. ...
NoSuchMethodException
reference:www.geeksforgeeks.com
IO exceptions example
public void inflate(int menuRes,Menu menu){
XmlResourceParser parser=null;
try {
parser=mContext.getResources().getLayout(menuRes);
AttributeSet attrs=Xml.asAttributeSet(parser);
parseMenu(parser,attrs,menu);
}
catch ( XmlPullParserException e) {
throw new InflateException("Error inflating menu XML",e);
}
catch ( IOException e) {
throw new InflateException("Error inflating menu XML",e);
}
finally {
if (parser != null) parser.close();
}
}
reference: www.javased.com
Interrupted exceptions
static public void spawnProcess(final List<String> cmd) {
if (cmd == null)
return;
Thread t = new Thread() {
public void run() {
Process proc = null;
proc = startProcess(cmd, true);
if (proc != null) {
consumeProcessOutput(proc);
try {
proc.waitFor();
}
catch (InterruptedException e) {
// ignore (we terminate anyway)
}
destroyProcess(proc);
}
Thread.currentThread().interrupt();
}
};
t.setDaemon(true);
t.start();
}
reference: www.programcreek.com
no such method exception
public static void main(String argv[]) throws NoSuchFieldException,
NoSuchMethodException {
if (argv.length == 1 && argv[0].equals("buildagent")) {
buildAgent();
return;
}
if (inst == null) {
throw new RuntimeException("Instrumentation object was null");
}
BufferedReader br;
String curline;
try {
br = new BufferedReader(new FileReader(filepath));
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}