Vatuu / discord-rpc

Java Wrapper of the Discord-RPC Library for Discord Rich Presence.
MIT License
194 stars 42 forks source link

Try / catch ignored? #39

Open aekramer opened 5 years ago

aekramer commented 5 years ago

Hi, first off thank you for this amazing rpc :)

But I have seem to encountered an issue, when people launch a second instance of the application, it will throw an error process already in use (this also happens if discord rpc is in use by something else right now). No issues there, but it throws a FileNotFoundException which I attempted to catch to neatly print that the RPC is disabled opposed to the stacktrace, and also disable usage for it later down the road. java.io.FileNotFoundException: C:\Users\Alex\AppData\Local\Temp\discord-rpc\discord-rpc.dll (The process cannot access the file because it is being used by another process) at java.io.FileOutputStream.open0(Native Method) at java.io.FileOutputStream.open(Unknown Source) at java.io.FileOutputStream.<init>(Unknown Source) at java.io.FileOutputStream.<init>(Unknown Source) at net.arikia.dev.drpc.DiscordRPC.openOutputStream(DiscordRPC.java:186) at net.arikia.dev.drpc.DiscordRPC.loadDLL(DiscordRPC.java:152) at net.arikia.dev.drpc.DiscordRPC.<clinit>(DiscordRPC.java:21) at com.runescape.Client.main(Client.java:4126)

Ive tried using a normal Try/Catch for FileNotFoundException but then Eclipse will tell me that this code will never throw this exception (except it already did), so instead I setup a general Exception clause, which seems completely ignored (the error message is never printed)

`try { DiscordEventHandlers handlers = new DiscordEventHandlers(); DiscordRPC.discordInitialize("123", handlers, true);

                DiscordRichPresence rich = new DiscordRichPresence.Builder("At login screen").build();
                DiscordRPC.discordUpdatePresence(rich);

                Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
                    @Override
                    public void run() {
                        DiscordRPC.discordShutdown();
                    }
                }));
            } catch (Exception e) {
                System.out.println("Failed connecting to discord: "+ e.getClass());
            }`