I'm using this code to set the macOS dock icon of my JavaFX app:
try {
// Sets macOS dock icon:
com.apple.eawt.Application.getApplication().setDockIconImage(SwingFXUtils.fromFXImage(appIcon, null));
} catch (Exception e) {
// Doesn’t work on Windows and Linux
}
I can't run the app on Windows because it throws the error "java: package com.apple.eawt does not exist"
How can I catch a "package x does not exist" error or check if it exists at runtime?