• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

InetAddress exception handling is getting in my way!

How do I implement this function without this pain in the butt exception handling getting in my way?

There is no way of creating an empty InetAddress object because new InetAddress() won't compile.

For this reason I have created my own IP address class that works the way I want it to work....except for this conversion function.

Is there any way to simply turn off exception handling in this function?

Code:
public InetAddress getIA()
{
    InetAddress ia;
    try
    {
        ia = InetAddress.getByAddress(m_arrayIP);
    }
    catch(IOException ioe)
    {
        System.out.println(ioe.getMessage());
        return;
    }
    return ia;
}
 
You know that exceptions happen for a reason don't you? i.e. something bad happened. You can't 'turn off' exception handling. You can choose not to catch a checked or unchecked exception, but if you don't then the JVM will, and your app will crash.

I assume that m_arrayIP is a byte[] array.

I also assume that this code generates an IOException, if so what is the reason given?
 
Yeah I realize exceptions serves a purpose, but they can also make coding rather inconvenient.....as in this case.
The exceptions employed by InetAddress prevent me from converting my IPAddress class to an InetAddress object as a function in my class.

I can only do it externally which means I have to repeat the same chunk of code multiple times.

I simple function return error code would be a lot better.
 
Back
Top Bottom