Hello! I've tried to use nothrow keyword and I couldn't get a state of function satisfied the keyword. I have one more method that can throw an exception; it is called inside nothrow method. Every type of an exception from the throwable method is handled by the nothow method.

ubyte throwable_fn(ubyte state) {
        if(state < 2) {
                return 1;
        } else if(state == 3) {
                throw new MyException1("qwe");
        } else {
                throw new MyException2("asd");
        }
}

void nothrowable_fn() nothrow {
        try {
                auto val = throwable_fn(3);
                // do success staff
        } catch(MyException1 e) {
                // handle error 1
        } catch(MyException2 e) {
                // handle error 2
        }
}


I can't compile this. I get an error says nothrowable_fn function can't be nothrow. I get the message until I handle Exception class. But it is not appropriate for me because I can get another exception of another type. I mean case when code will be updated and new exceptions will come with a new piece of code.

How can I achieve nothrow statement without catching of an instance of Exception class? Thanks. Sorry if my English is not clear.

Reply via email to