Back to project page Android-CleanArchitecture.
The source code is released under:
Apache License
If you think the Android project Android-CleanArchitecture listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * Copyright (C) 2014 android10.org. All rights reserved. * @author Fernando Cejas (the android10 coder) */// w ww. j a v a 2 s . c o m package com.fernandocejas.android10.sample.presentation.exception; import android.content.Context; import com.fernandocejas.android10.sample.data.exception.NetworkConnectionException; import com.fernandocejas.android10.sample.data.exception.UserNotFoundException; import com.fernandocejas.android10.sample.presentation.R; /** * Factory used to create error messages from an Exception as a condition. */ public class ErrorMessageFactory { private ErrorMessageFactory() { //empty } /** * Creates a String representing an error message. * * @param context Context needed to retrieve string resources. * @param exception An exception used as a condition to retrieve the correct error message. * @return {@link String} an error message. */ public static String create(Context context, Exception exception) { String message = context.getString(R.string.exception_message_generic); if (exception instanceof NetworkConnectionException) { message = context.getString(R.string.exception_message_no_connection); } else if (exception instanceof UserNotFoundException) { message = context.getString(R.string.exception_message_user_not_found); } return message; } }