Code to create generic alert dialog to display error messages in Android

While error handling in Android java, use below code as reference to create generic alert dialog to display required error messages. Below is Android Java code,
private void doStuff() { try { //do some stuff here } catch(Exception e) { messageBox("doStuff", e.getMessage()); } } //********************************************************* //generic dialog, takes in the method name and error message //********************************************************* private void messageBox(String method, String message) { Log.d("EXCEPTION: " + method, message); AlertDialog.Builder messageBox = new AlertDialog.Builder(this); messageBox.setTitle(method); messageBox.setMessage(message); messageBox.setCancelable(false); messageBox.setNeutralButton("OK", null); messageBox.show(); }
Sign In or Register to comment.