Lew wrote:
at least log the Exception.
For example, assuming log4j:
import org.apache.log4j.Logger;
public class SomethingOrOther
{
private Logger logger = Logger.getLogger( getClass() );
public static void main( String [] args )
{
try
{
doSomethingThatMightThrowAnException();
}
catch( AnException exc )
{
String msg = "AnException: "+ exc;
logger.error( msg ); // /* or use */ System.err.println( msg );
}
}
}
I made several mistakes in this example, at least one carelessly. It
wasn't meant to be compilable anyway, but I really shouldn't have mixed
static and instance stuff:
import org.apache.log4j.Logger;
public class SomethingOrOther
{
static class AnException extends Exception
{
public AnException(){}
public AnException( String msg ){ super( msg ); } // other two omitted
}
private final Logger logger = Logger.getLogger( getClass() );
private void doSomething() throws AnException
{
throw new AnException("oops");
}
public final void handle()
{
try
{
doSomething();
System.out.println( "Success" );
}
catch( AnException exc )
{
String msg = "AnException: "+ exc;
logger.error( msg ); // /* or use */ System.err.println( msg );
}
}
public static void main( String [] args )
{
SomethingOrOther soo = new SomethingOrOther();
soo.handle();
}
}
.... non comprende, monsiuer. wouldn't it be easier to just put a
will never get there. we catch for show.
Sometimes I'm in a good mood.
Sometimes I'm in a bad mood.