so if I have
try{
//random stuff
}
catch(Exception ex){
CallbackHelper.say("Error in (insert meathod name here)");
CallbackHelper.say(ex.toString());
}
where CallbackHelper is a static class with the callback and say is a method that does getGame().sendTextMessage(string, 0), is there a way to get a more detailed error report than, say, java.lang.nullPointerException?
Like I want to at least see a line number. Is there a way?
JavaAI how to find error number
Moderators: hoijui, Moderators
Re: JavaAI how to find error number
Of course there is
Here's how I do it:
and then
will write something like
Here's how I do it:
Code: Select all
public class Logger {
private static final PrintWriter writer;
static {
try {
String filename = "merai-" + MerAI.callback.getSkirmishAI().getTeamId() + ".log";
String path = MerAI.callback.getDataDirs().allocatePath(filename, true, true, false, false);
writer = new PrintWriter(new FileOutputStream(path));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
public static void log(String msg) {
writer.println(msg);
}
public static void log(Throwable t) {
t.printStackTrace(writer);
}
public static void shutdown() {
writer.close();
}
}
Code: Select all
@Override
public int unitIdle(Unit unit) {
try {
// code to handle the event goes here
return 0;
} catch (Throwable t) {
Logger.log(t);
return -1;
}
}
to the log file. This is known as a stack trace. See http://stackoverflow.com/questions/1268 ... tack-trace on how to interpret them.java.lang.RuntimeException: no site found!
at merai.Builder$BuildAction.perform(Builder.java:59)
at merai.MerAI.unitIdle(MerAI.java:40)
at merai.MerAI.unitFinished(MerAI.java:51)
at com.springrts.ai.oo.OOAI.unitFinished(OOAI.java:116)
Re: JavaAI how to find error number
Ahh.. I was kind of hoping there was an easier way to find just the line number and print it onto the Spring log as I wouldn't have to worry about a separate log file, but thanks!
Re: JavaAI how to find error number
You can of course write it to the spring log file instead:
The reason I write to a separate file is that I also want to emit other diagnostic information, making the log quite large. Writing to the spring log is both somewhat slower, and spams the ingame console, distracting the player.
Code: Select all
} catch (Throwable t) {
StringWriter sw = new StringWriter();
t.printStackTrace(sw);
writeToConsole(sw.toString);
}
Re: JavaAI how to find error number
I get an error saying that stringwriter can't be converted to printwritermeriton wrote:You can of course write it to the spring log file instead:
The reason I write to a separate file is that I also want to emit other diagnostic information, making the log quite large. Writing to the spring log is both somewhat slower, and spams the ingame console, distracting the player.Code: Select all
} catch (Throwable t) { StringWriter sw = new StringWriter(); t.printStackTrace(sw); writeToConsole(sw.toString); }
Re: JavaAI how to find error number
why does sendTextMessage(ex.getMessage()) always cause spring to crash?
Re: JavaAI how to find error number
can you provide more details? infolog.txt could be useful...Bla wrote:why does sendTextMessage(ex.getMessage()) always cause spring to crash?
Re: JavaAI how to find error number
Hm kind of late reply, as I have not ran into many bugs, but in the infolog, it just cuts out. It just ends there.abma wrote:can you provide more details? infolog.txt could be useful...Bla wrote:why does sendTextMessage(ex.getMessage()) always cause spring to crash?
Re: JavaAI how to find error number
try set LogFlush = 1 (should be default)...