How about create another class like this.
public class Log{
FileConnection fc;
OutputStream outStream;
InputStream inStream;
Log(String exceptionClass, String errorMessage){
try{
fc = (FileConnection)Connector.open("[path]");
if(!fc.exists()) fc.create();
inStream = fc.openInputStream();
outStream = fc.openOutputStream();
if(inStream!=null)
outStream.write(IOUtilities.streamToBytes(instream)); //use this so overwriting is enabled
outStream.write((exceptionClass+"\n").getBytes());
outStream.write((errorMessage+"\n").getBytes());
}
catch(IOException e){}
finally{
try{
inStream.close();
outStream.close();
fc.close();
}catch(Exception e){}
}
}
}
Then just call your Log class at every catch of your try block:
e.g.
try{
//your process
}catch(Exception e){
//call log
new Log(e.getClassName(), e.getMessage());
}
you can modify it, better if you write date and time for each log.