Catch specific Java errors in javascript

Enonic version: 6.9.2
OS: Mac

How do I catch Java error in my js controllers?

This code:

if (e instanceof com.enonic.xp.repo.impl.repository.RepositoryAlreadyExistException)

Gives me this error:

TypeError: instanceof must be called with a javascript or java object as the right-hand argument (com.enonic.xp.resource.ResourceProblemException)

Try something like this:

try {
    doSomething();
} catch (e) {
    if (e.class.name === 'com.enonic.xp.repo.impl.repository.RepositoryAlreadyExistException') {
        handleRepoExists();
    }
}
3 Likes