better (?) error handling

This commit is contained in:
rusEfi 2020-02-22 15:17:30 -05:00
parent b01a2cf4c8
commit dd07e37ab3
1 changed files with 7 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package com.rusefi;
import com.opensr5.Logger;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -126,14 +127,18 @@ public enum FileLog {
public void log(Throwable exception) {
if (fileLog == null)
throw new NullPointerException("fileLog");
throw new NullPointerException("fileLog while " + exception);
OutputStreamWriter os = new OutputStreamWriter(fileLog);
exception.printStackTrace(new PrintWriter(os));
}
public void logException(String msg, Throwable e) {
logLine(msg + e);
log(e);
e.printStackTrace();
if (fileLog == null) {
JOptionPane.showConfirmDialog(null, msg + " " + e, "no log and Exception Occurred", JOptionPane.DEFAULT_OPTION);
return;
}
log(e);
}
}