简体   繁体   中英

Custom lexer Error Message in JavaCC

I want to customize the lexer error message, I have my exception class that subclasses TokenMgrError and redefined the function but how do I ensure that in Lexer2TokenManager class, that it will do

throw new mysubclassexception(.........)

instead of

throw new TokenMgrError(.......)

Could the documentation that the comments refer to be out of date?

Whenever I want to use a custom exception class I insert a try / catch block in my production rules. Something along the lines of this;

(
  ...
  { 
    try {
      ...
    } catch (Exception e) {
      ...
      throw new MyCustomException ( e, customMessage );
    }
  }
)

Perhaps not the most elegant solution but it has always been adequate for me. Hope it helps.

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