Android, comment faire pour afficher une boîte de dialogue d'erreur sur un try catch?

Dans mon application je me connecte à un site web pour recueillir des informations, à commencer par un AsyncTask, à l'aide d'un try catch, à partir d'ici, je peux afficher dans mon catlog l'erreur si quelqu'un à la connexion, mais j'ai essayé avec de la chance pour afficher une boîte de dialogue affichage de l'échec de la connexion avec les options de reconnecter ou de cesser de fumer, veuillez vérifier mon code et me dire ce que je fais mal ou une idée de comment procéder

 //this is our download file asynctask
class DownloadFileAsync extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(DIALOG_DOWNLOAD_PROGRESS);
}
@Override
protected String doInBackground(String... aurl) {
try {
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://mywebsiteaddress");
//httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream webs = entity.getContent();
//convert response to string
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(webs, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
webs.close();
result = sb.toString();
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
//parse json data
try {
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
webResult resultRow = new webResult();
//infotodownload
arrayOfWebData.add(resultRow);
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
} catch (Exception e) {
//this is the line of code that sends a real error message to the
//log
Log.e("ERROR", "ERROR IN CODE: " + e.toString());
//this is the line that prints out the location in
//the code where the error occurred.
e.printStackTrace();
}
return null;
}
protected void onProgressUpdate(String... progress) {
Log.d(LOG_TAG,progress[0]);
mProgressDialog.setProgress(Integer.parseInt(progress[0]));
}
@Override
protected void onPostExecute(String unused) {
//dismiss the dialog after the file was downloaded
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
}
}
//our progress bar settings
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_DOWNLOAD_PROGRESS: //we set this to 0
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setTitle("Conectando al Servidor");
mProgressDialog.setMessage("Cargando informacion...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.setMax(100);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setCancelable(true);
mProgressDialog.show();
return mProgressDialog;
default:
return null;
}
}

EDIT:
ensuite j'ai essayer d'ajouter le code suivant comme suggéré par Arun

 catch (Exception e) {
//this is the line of code that sends a real error message to the
//log
Log.e("ERROR", "ERROR IN CODE: " + e.toString());
//this is the line that prints out the location in
//the code where the error occurred.
e.printStackTrace();
return "ERROR_IN_CODE";
}
return null;       //if I place here return "ERROR_IN_CODE" it calls the dialog but it gets always called so I don't need it here
}
@Override
protected void onPostExecute(String unused) {
//dismiss the dialog after the file was downloaded
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
if(unused.equals("ERROR_IN_CODE")){                 //I get a system crash here!
errornote();
}
}
}
public void errornote() {
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
alt_bld.setMessage("No se a podido descargar la informacion de los medios, deseas reintentarlo, o salir?").setCancelable(false)
.setPositiveButton("Conectar de Nuevo", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
new DownloadFileAsync().execute();
}
})
.setNegativeButton("Salir", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//Action for 'NO' Button
finish();
}
});
AlertDialog alert = alt_bld.create();
//Title for AlertDialog
alert.setTitle("Error en la Conexion!");
//Icon for AlertDialog
alert.setIcon(android.R.drawable.ic_dialog_alert);
alert.show();
}

mais ne fonctionne pas non plus, mon application se bloque dans l'instruction if ligne dans onPostExecute. J'ai encore besoin d'aide.

Vous ne pouvez pas afficher la boîte de dialogue dans le bloc Catch de doInBackground() car cette fonction s'exécute dans un thread non-INTERFACE utilisateur
Voir si la réponse here aide.
pas de la boîte de dialogue n'apparaît pas.
Selon la dernière ÉDITION, il semble exécution de code ne s'exécute pas dans le bloc catch, assurez-vous de bloc catch est déclenché correctement, dans un autre mot, assurez-vous que le code dans le bloc try a échoué et jeter le réel de l'exception.
yorkw, ce que j'ai fait pour tester c'est juste débrancher mon internet à partir de l'ordinateur de cette façon, lorsque l'émulateur est à essayer de se connecter pour télécharger l'info, il ne sera pas en mesure de sorte qu'il permettra d'obtenir une erreur de connexion. est-ce que vous vouliez dire?

OriginalL'auteur zvzej | 2012-06-08