dimanche 1 août 2021

Intercept method errors in java

I wanted to know if it is possible and if is what is the best way to intercept errors when calling a method, example so you can understand better.

ErrorHandler.invoke(RepositoryManager.find(Types.valueOf("THROW_ERROR")) // The method here (this will throw exception)
            .interceptError(Enum.class) // valueOf intercept when cannot find the enum (exception from the Enum.class)
            .withMessage(e -> "can't find enum " + e); // The message when cannot find the enum

its possible make something like that or something similar, any ideas?





Aucun commentaire:

Enregistrer un commentaire