Throw more exceptions

We want to know when the code is wrong instead of silently failing
This commit is contained in:
Sylvia van Os
2022-08-25 19:28:09 +02:00
parent 646dab336d
commit 83d19c30c2
2 changed files with 18 additions and 12 deletions

View File

@@ -975,16 +975,12 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
try {
if (requestCode == PERMISSION_REQUEST_CAMERA_IMAGE_FRONT) {
takePhotoForCard(Utils.CARD_IMAGE_FROM_CAMERA_FRONT);
} else if (requestCode == PERMISSION_REQUEST_CAMERA_IMAGE_BACK) {
takePhotoForCard(Utils.CARD_IMAGE_FROM_CAMERA_BACK);
} else if (requestCode == PERMISSION_REQUEST_CAMERA_IMAGE_ICON) {
takePhotoForCard(Utils.CARD_IMAGE_FROM_CAMERA_ICON);
}
} catch (Exception e) {
e.printStackTrace();
if (requestCode == PERMISSION_REQUEST_CAMERA_IMAGE_FRONT) {
takePhotoForCard(Utils.CARD_IMAGE_FROM_CAMERA_FRONT);
} else if (requestCode == PERMISSION_REQUEST_CAMERA_IMAGE_BACK) {
takePhotoForCard(Utils.CARD_IMAGE_FROM_CAMERA_BACK);
} else if (requestCode == PERMISSION_REQUEST_CAMERA_IMAGE_ICON) {
takePhotoForCard(Utils.CARD_IMAGE_FROM_CAMERA_ICON);
}
}
}
@@ -1220,6 +1216,10 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity {
callable.call();
} catch (Exception e) {
e.printStackTrace();
// Rethrow as NoSuchElementException
// This isn't really true, but a View.OnClickListener doesn't allow throwing other types
throw new NoSuchElementException(e.getMessage());
}
})
.show();

View File

@@ -252,8 +252,14 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
@Override
protected void onCreate(Bundle savedInstanceState) {
if (savedInstanceState == null) {
Intent incomingIntent = getIntent();
int transitionRight = incomingIntent.getExtras().getInt("transition_right", -1);
Bundle incomingIntentExtras = getIntent().getExtras();
if (incomingIntentExtras == null) {
Toast.makeText(this, R.string.noCardExistsError, Toast.LENGTH_LONG).show();
finish();
}
int transitionRight = incomingIntentExtras.getInt("transition_right", -1);
if (transitionRight == 1) {
// right side transition
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);