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:

  1. handle exception inside visitor method itself.
  2. 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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -