antlr4 - Checked exceptions in visitors -
i learning antlr4 , have no previous experience parser generators.
when define own visitor implementation, have override methods of basevisitor (i looking instance @ evalvisitor class @ page 40 of book). in case method implementation possibly throws exception, should do? cannot use checked exception since original method has empty throws clause. expected use unchecked exceptions? (this seems bad java design). instance, assume in evalvisitor class want method visitid (page 41) throw user-defined exception, undefinedid, rather returning 0. how should write code?
you have 2 options:
- handle exception inside visitor method itself.
wrap checked exception in unchecked exception. 1 possibility
parsecancellationexception, you'll have determine whether or not makes sense in application.try { ... } catch (ioexception ex) { throw new parsecancellationexception(ex); }
Comments
Post a Comment