简体   繁体   中英

Custom Exception that throws only specific Exceptions

I have a method which will throw SecurityException,NoSuchFieldException, IllegalArgumentException, IllegalAccessException.

I want to Custom Exception clause so that it will throw only the above Exception.

If any other exception comes, my Custom Exception clause should not throw it.

Is there a way or two to do this?

Thanks.

May be you can test the type of exception, for example:

if (e instanceof SecurityException) {
    // do sth;
} else if (e instanceof NoSuchFieldException) {
    // do sth;
} else if (e instanceof IllegalArgumentException) {
    // do sth;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM