Skip to content

Commit d942d06

Browse files
committed
System Touch
1 parent 634126e commit d942d06

4 files changed

Lines changed: 30 additions & 16 deletions

File tree

source/exceptions/ExceptionEventDispatcher.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,17 @@ public void dispatch(final Exception EX)
2626

2727
for (ExceptionListener listener : LISTENERS)
2828
{
29-
listener.onException(record);
29+
try
30+
{
31+
listener.onException(record);
32+
}
33+
catch (Exception listenerEx)
34+
{
35+
// Listener itself threw — print directly to stderr, do NOT re-dispatch
36+
// (re-dispatching here is what causes the infinite loop).
37+
System.err.println("[DISPATCHER] Listener " + listener.getClass().getSimpleName()
38+
+ " threw: " + listenerEx.getMessage());
39+
}
3040
}
3141

3242
if (SETTINGS.isPersistExceptions())

source/exceptions/ExceptionHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,22 @@ public class ExceptionHandler
1717

1818
private ExceptionHandler()
1919
{
20-
ExceptionPersistenceService persistence = new ExceptionPersistenceService("/logging/exceptions.log");
20+
ExceptionPersistenceService persistence = new ExceptionPersistenceService("logging/exceptions.log");
2121

2222
BackendSettings settings = new BackendSettings(
2323
true,
24-
"/logging/exceptions.log",
24+
"logging/exceptions.log",
2525
List.of(
2626
new SecurityExceptionHandler(),
2727
new NullPointerConstructorHandler(),
28-
new PersistenceListener("/logging/exceptions.log")
28+
new PersistenceListener("logging/exceptions.log")
2929
)
3030
);
3131

3232
dispatcher = new ExceptionEventDispatcher(
3333
List.of(
3434
new SecurityExceptionHandler(),
3535
new NullPointerConstructorHandler(),
36-
new PersistenceListener("/logging/exceptions.log"),
3736
new N21ExceptionListener()
3837
),
3938
persistence,

source/exceptions/ExceptionPersistenceService.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ public ExceptionPersistenceService(final String FILEPATH)
2222
*/
2323
public void persist(final ExceptionRecord RECORD)
2424
{
25-
try
25+
File file = new File(FILEPATH);
26+
27+
File parent = file.getParentFile();
28+
if (parent != null && !parent.exists() && !parent.mkdirs())
2629
{
27-
new File(FILEPATH).getParentFile().mkdirs();
30+
System.err.println("[PERSISTENCE-ERROR] Cannot create log directory: " + parent.getAbsolutePath());
31+
return;
2832
}
29-
catch (Exception ignored) {}
3033

31-
try (FileWriter writer = new FileWriter(FILEPATH, true))
34+
try (FileWriter writer = new FileWriter(file, true))
3235
{
33-
3436
writer.write("[EXCEPTION] " + Instant.now() + System.lineSeparator() +
3537
"Type: " + RECORD.EXCEPTION().getClass().getName() + System.lineSeparator() +
3638
"Message: " + RECORD.EXCEPTION().getMessage() + System.lineSeparator() +
@@ -40,8 +42,8 @@ public void persist(final ExceptionRecord RECORD)
4042
"------------------------------------------------------------" +
4143
System.lineSeparator()
4244
);
43-
44-
} catch (IOException ioEx)
45+
}
46+
catch (IOException ioEx)
4547
{
4648
System.err.println("[PERSISTENCE-ERROR] Failed to write exception RECORD: " + ioEx.getMessage());
4749
}

source/exceptions/PersistenceListener.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ public void onException(final ExceptionRecord RECORD)
3030

3131
private void writeRecordToFile(final ExceptionRecord RECORD)
3232
{
33-
try
33+
File file = new File(FILEPATH);
34+
35+
File parent = file.getParentFile();
36+
if (parent != null && !parent.exists() && !parent.mkdirs())
3437
{
35-
new File(FILEPATH).getParentFile().mkdirs();
38+
System.err.println("[PERSISTENCE-ERROR] Cannot create log directory: " + parent.getAbsolutePath());
39+
return;
3640
}
37-
catch (Exception ignored) {}
3841

39-
try (FileWriter writer = new FileWriter(FILEPATH, true))
42+
try (FileWriter writer = new FileWriter(file, true))
4043
{
4144
writer.write("[EXCEPTION] " + Instant.now() + System.lineSeparator() + "Type: " + RECORD.EXCEPTION().getClass().getName() + System.lineSeparator() + "Message: " + RECORD.EXCEPTION().getMessage() + System.lineSeparator() + "Origin: " + RECORD.ORIGIN() + System.lineSeparator() + "StackTrace: " + RECORD.STACKTRACE() + System.lineSeparator() + "------------------------------------------------------------" + System.lineSeparator());
4245
}

0 commit comments

Comments
 (0)