Created
August 9, 2013 02:42
-
-
Save Chris-Gillis/6190773 to your computer and use it in GitHub Desktop.
Good use of a try-catch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try | |
{ | |
// Some code that can fail | |
} | |
catch(NumberFormatException e) | |
{ | |
Log.v(TAG, "User entered invalid data: carbs - " + carbsString + " fiberString - " + fiberString); | |
// I feel dirty for this hack | |
mCarbsAmountEditText.removeTextChangedListener(mCarbsTextWatcher); | |
mCarbsAmountEditText.setText(""); | |
mCarbsAmountEditText.addTextChangedListener(mCarbsTextWatcher); | |
mFiberAmountEditText.removeTextChangedListener(mFiberTextWatcher); | |
mFiberAmountEditText.setText(""); | |
mFiberAmountEditText.addTextChangedListener(mFiberTextWatcher); | |
updateNetCarbs(); | |
View toastLayout = getLayoutInflater().inflate(R.layout.toast_layout, | |
(ViewGroup) findViewById(R.id.toast_layout_root)); | |
TextView text = (TextView)toastLayout.findViewById(R.id.toastTextView); | |
text.setText(R.string.toastErrorMessage); | |
Toast errorToast = new Toast(getApplicationContext()); | |
errorToas t.setGravity(Gravity.TOP, 0, 0); | |
errorToast.setDuration(Toast.LENGTH_LONG); | |
errorToast.setView(toastLayout); | |
errorToast.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment