我想抓住这个错误,以便我自己处理它而不是向用户显示它。我该怎么办?
我正在使用官方SDK for Android for Windows Azure。
此错误仅在2-3%的时间内出现。所有其他时间它连接正常。
此外,如果我尝试联系azure的活动不存在,则上下文不再存在,并且它会尝试在不存在的上下文中显示该消息,这将使应用程序崩溃。
此代码基本上是来自windows azure的todolist示例。
谢谢,
Anthony G。
try {
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
mClient = new MobileServiceClient(
"XXXXXXX",
"YYYYYYYYY", this)
.withFilter(new ProgressFilter());
createTable();
} catch (MalformedURLException e) {
createAndShowDialog(
new Exception(
"There was an error creating the Mobile Service. Verify the URL"),
"Error");
} catch (Exception e) {
Log.d(TAG, "Exepction caught" + e.toString());
}
这是表创建部分。
try {
Log.d(TAG, "Create table called and started. ");
// Get the Mobile Service Table instance to use
// Don't use the default, because the table on Azure has a different name than the class, instead use this call.
mToDoTable = mClient.getTable("MY_TABLE",
MY_TABLE_SPECIAL_CLASS.class);
// Create an adapter to bind the items with the view
mAdapter = new DownloadedMapsListAdapter(this, R.layout.row_list_show_maps_to_download);
ListView listViewToDo = (ListView) findViewById(R.id.listview_data_fromAzure);
//listViewToDo.setOnItemClickListener(mMessageClickedHandler);
listViewToDo.setAdapter(mAdapter);
// Load the items from the Mobile Service
refreshItemsFromTable();
} catch (Exception e) {
Log.d(TAG, "Exepction caught" + e.toString());
}
答案 0 :(得分:0)
好的,我是个偶像。在refreshItemsFromTable()中,正在调用实际的'execute'语句(我没有在我的问题中发布它)。执行是它实际联系Azure时。该函数检查异常是否为null而不是使用try-catch。所以显示的是CreateAndShowDialog(异常,字符串)。
也许这会帮助别人。
/**
* Refresh the list with the items in the Mobile Service Table
*/
private void refreshItemsFromTable() {
// Get the items that weren't marked as completed and add them in the
// adapter
Log.d(TAG, "refreshItemsFromTable");
mToDoTable.execute(new TableQueryCallback<MapObjects_FromAzure>() {
public void onCompleted(List<MapObjects_FromAzure> result, int count,
Exception exception, ServiceFilterResponse response) {
if (exception == null) {
Log.d(TAG,
"refreshItemsFromTable on complete, with no exception thrown so far. ");
mAdapter.clear();
for (MapObjects_FromAzure item : result) {
mAdapter.add(item);
}
} else {
createAndShowDialog(exception,
"Error" + exception.toString());
}
}
});