I want to throw a specific exception for a block of code without creating a new class. Is there any way to throw an exception with a specific code and catch it with this code identifier?
try {
//Do something
if(somevalue)
throw new Exception(667);
} catch (Exception e) {
if(e.getCode() == 667) {
//Do something
}
System.out.println("Something went wrong.");
}