I am trying to pass an exception to an activity meant to dump the relevant information to the screen.
Currently I pass it through a bundle:
try {
this.listPackageActivities();
} catch (Exception e) {
Intent intent = new Intent().setClass(this, ExceptionActivity.class).putExtra("Exception", e);
startActivity(intent);
}
But when it gets there:
if (!(this.bundle.getParcelable("Exception") != null))
throw new IndexOutOfBoundsException("Index \"Exception\" does not exist in the parcel." + "/n"
+ "Keys: " + this.bundle.keySet().toString());
This sweet exception is thrown but when I look at the keySet and the bundle details it tells me that there is one parcelable object with a key named “Exception”.
I understand that this has something to do with types but I do not understand what I am doing wrong. I just want to dump information about an exception, any exception to the screen. Is there a way to do that without having to condense all the information into a string every time?
I stumbled on this question when I was searching for a method to pass exceptions from a service to an activity. However, I found a better method, you can use the
putSerializable()method of the Bundle class.To add:
To retrieve: