Building own try/catch

Hi,

guess this is a more difficult question to answer .. hope there is still an (easy) solution available :)

(1) I have a concept MyStatementList extending StatementList.
(2) I can use MyStatementList in a simple java class

     MyStatementList {
        FileInputStream f = new FileInputStream("dan");
     }

(3) Of course, MPS will now mark the 'new FileInputStream("  ")' with
    'uncaught Excpetion "java.io.FileNotFoundException"'

(4) I will catch that exception in the code-generator. So how can i add some support to
    MyStatementList in order to mark the Exception as catched?


I guess this is not easily possible. I checked the try/catch ... lots of code ...


Dan
2 comments
Add the interfaces IMethodLike and IStatementListContainer to your concept and implement the required behavior methods as follows
public node<StatementList> getBody() 
  overrides IMethodLike.getBody { 
  this; 
}        
 
public node<> getExpectedRetType() 
  overrides IMethodLike.getExpectedRetType { 
  null; 
}              
 
public nlist<Type> getThrowableTypes() 
  overrides IMethodLike.getThrowableTypes { 
  new nlist<Type>; 
}
 
public boolean implicitThrows() 
  overrides IMethodLike.implicitThrows { 
  true; 
}      
prettyPrint();

If you want to catch specific exceptions only remove the method implicitThrows and return the exception types in getThrowableTypes
0

Please sign in to leave a comment.