public class ApplicationException extends Exception
{
private static final long serialVersionUID = 1L;
public ApplicationException()
{
super();
}
public ApplicationException(String message)
{
super(message);
}
}
public class Utilities
{
public static byte[] ParseHehadecimalString(String s) // error 1
{
throw new ApplicationException("ParseHehadecimalString not implemented");
}
}
public class Client extends Activity {
{
public void OnBtnSendClick(View v)
{
String s = et_client_out.getText().toString();
byte[] bytes;
try
{
bytes = Utilities.ParseHehadecimalString(s);
}
catch(ApplicationException ex) // error 2
{
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_SHORT).show();
return;
}
}
Error 1: Unhandled exception type ApplicationException
Error 2: Unreachable catch block for ApplicationException. This exception is never thrown from the try statement body
How this can be fixed?
error 1 needs to look like
error 2 does not through this exception because of error 1. Once error 1 is fixed errror 2 will disappear
This link describes how to add exceptions to method signatures.