我正在使用 Android 的 httpclient 连接到域,如下所示:
try {
URL url = new URL("example.com");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
read(conn.getInputStream());
} catch (Exception e) {
e.printStackTrace();
}
现在如果我删除此行可以吗:
e.printStackTrace();
并将其替换为:
Toast toast = Toast.makeText(getApplicationContext(), "Could not connect to domain.", Toast.LENGTH_LONG);
toast.show();
还是我必须对“e”变量做些什么?在这种情况下,它将是:
catch (Exception e) {
e.printStackTrace();
Toast toast = Toast.makeText(getApplicationContext(), "Could not connect to domain.", Toast.LENGTH_LONG);
toast.show();
}
如果我执行 e.printStackTrace(),它会打印到哪里?