Skip to content

Commit

Permalink
improve Error Handling on BlockNodeApp, webServer Start, added a new …
Browse files Browse the repository at this point in the history
…UnhandledIOException that is a runtime wrapper for the checked IOException

Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Aug 22, 2024
1 parent 0ad8a3a commit ae78e6d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/src/main/java/com/hedera/block/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.hedera.block.server;

import com.hedera.block.server.exception.UnhandledIOException;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;

Expand All @@ -38,12 +39,13 @@ public static void main(final String[] args) {
@NonNull
final BlockNodeAppInjectionComponent daggerComponent =
DaggerBlockNodeAppInjectionComponent.create();
@NonNull final BlockNodeApp server = daggerComponent.getBlockNodeApp();
@NonNull final BlockNodeApp blockNodeApp = daggerComponent.getBlockNodeApp();

try {
server.startServer();
blockNodeApp.startServer();
} catch (IOException e) {
throw new RuntimeException(e);
LOGGER.log((System.Logger.Level.ERROR), "Failed to start server", e);
throw new UnhandledIOException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.hedera.block.server.exception;

import java.io.Serial;

/**
* UnhandledIOException is a RuntimeException that wraps an IOException.
* This can be used to rethrow checked IOExceptions as unchecked exceptions.
*/
public class UnhandledIOException extends RuntimeException {

@Serial
private static final long serialVersionUID = 1L;

/**
* Constructs a new UnhandledIOException with the specified cause.
*
* @param cause the underlying IOException that caused this exception
*/
public UnhandledIOException(final Throwable cause) {
super(cause);
}
}

0 comments on commit ae78e6d

Please sign in to comment.