문제

I'm using Android SAX parser which allows to bind listeners to EndTextElementListener event, however the listeners provided by Android don't allows us to throw exceptions, so for example how do i stop the parser during the process ?

Some code:

item.getChild("child").setEndTextElementListener( new EndTextElementListener() {
        @Override
        public void end(String s) {

            if( expression )
                throw new CustomException(); //Can't do this because end method don't throw SaxExceptions

        }
    });

CustomException extends SaxException by the way. But the listeners don't throw SaxExceptions so is there any way of doing it ? Or switching to a pull parser is the only option ?

도움이 되었습니까?

해결책

If you don't care about exactly what type of exception is thrown, then throw a sub-class of RuntimeException. The compiler will allow this.

if( expression )
    throw new MyCustomException();
}

where:

class MyCustomException extends RuntimeException ...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top