Skip to content

Commit

Permalink
Improved error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Butler committed Jan 27, 2011
1 parent c057bfa commit 5dfc671
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
24 changes: 21 additions & 3 deletions src/com/codebutler/farebot/Utils.java
Expand Up @@ -37,12 +37,11 @@ public class Utils
{
public static void showErrorAndFinish (final Activity activity, Exception ex)
{
String text = (ex.getMessage() == null) ? ex.toString() : ex.getMessage();
Log.e(activity.getClass().getName(), text);
Log.e(activity.getClass().getName(), Utils.getErrorMessage(ex));
ex.printStackTrace();

new AlertDialog.Builder(activity)
.setMessage(text)
.setMessage(Utils.getErrorMessage(ex))
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Expand Down Expand Up @@ -122,4 +121,23 @@ public static String xmlDocumentToString (Document doc) throws Exception
transformer.transform(source, result);
return stringWriter.getBuffer().toString();
}

public static String getErrorMessage (Throwable ex)
{
String errorMessage = null;
if (ex.getCause() != null) {
errorMessage = ex.getCause().getLocalizedMessage();
if (errorMessage == null)
errorMessage = ex.getCause().getMessage();
if (errorMessage == null)
errorMessage = ex.getCause().toString();
} else {
errorMessage = ex.getLocalizedMessage();
if (errorMessage == null)
errorMessage = ex.getMessage();
if (errorMessage == null)
errorMessage = ex.toString();
}
return errorMessage;
}
}
Expand Up @@ -26,7 +26,6 @@
import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.nfc.INfcTag;
import android.nfc.NfcAdapter;
import android.os.AsyncTask;
import android.os.Bundle;
Expand All @@ -40,9 +39,6 @@
import com.codebutler.farebot.provider.CardsTableColumns;
import com.codebutler.nfc.NfcInternal;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ReadingTagActivity extends Activity
{
@Override
Expand Down Expand Up @@ -84,7 +80,7 @@ protected MifareCard doInBackground (Object... params) {
if (cardType.equals("Iso14443-4"))
return DesfireCard.dumpTag(id, tagObject);
else
throw new Exception("Unsupported card type: " + cardType);
throw new Exception(String.format("Unsupported card type: %s\nSerial: %s", cardType, Utils.getHexString(id)));
} catch (Exception ex) {
mException = ex;
return null;
Expand Down

0 comments on commit 5dfc671

Please sign in to comment.