Java ClassNotFoundException Handling Is there a better way to handle this ClassNotFoundException ?

private Class&lt;?&gt; getClass(String value)
{
    Class&lt;?&gt; columnClass = null;
    try
    {
        columnClass = Class.forName(StringUtils.trim(value));
    }
    catch (ClassNotFoundException ex)
    {
        if (value.contains("double") || value.contains("Double"))
        {
            columnClass = Double.class;
        }
        else if (value.contains("int") || value.contains("Int"))
        {
            columnClass = Integer.class;
        }
        else if (value.contains("bool"))
        {
            columnClass = Boolean.class;
        }
        else if (value.contains("long") || value.contains("Long"))
        {
            columnClass = Long.class;
        }
        else
        {
            log.error("FAILED. Class object is not supported: " + value, ex);
        }
    }
    return columnClass;
}
You do not provide much context for this method, so I can only give you general advice.
Logic

never use exception handling as part of the routine/regular code path in you program. Most Java VM's require significant locking and processing to generate the actual exception and its stack trace. I have seen 10% performance improvements in large commercial applications where simple pre-validation of common exceptional conditions saves a huge amount of processing resources.

What if the user enters the non-existent class name dev.null.TurningIntoZomies, they get an Integer.class back.

In the event that the Class.forname(...) fails, you do exception handling and return null. If the program asks for the same value again, it will do the full search again, and so on. If the class exists, it is not normally very slow, but, if the class does not exist, the Class.forname() has to search the entire classpath. Cache the results (of both the successes and the failures so you only have to call Class.forName() once.


Code Style

Use correct Java brace placement, at the end of the line.

Finally, you can use short-circuit return statements to make it easier:
private Class&lt;?&gt; getClass(String value) {
    try {
        return Class.forName(StringUtils.trim(value));
    } catch (ClassNotFoundException ex) {
        if (value.contains(&quot;double&quot;) || value.contains(&quot;Double&quot;)) {
            return Double.class;
        }
        if (value.contains(&quot;int&quot;) || value.contains(&quot;Int&quot;)) {
            return Integer.class;
        }
        if (value.contains(&quot;bool&quot;)) {
            return = Boolean.class;
        }
        if (value.contains(&quot;long&quot;) || value.contains(&quot;Long&quot;)) {
            return Long.class;
        }
        log.error(&quot;FAILED. Class object is not supported: &quot; + value, ex);
        return null;

    }
}