@@ -330,12 +330,23 @@ public ParseTree visitTryStatement(BSLParser.TryStatementContext ctx) {
330
330
// весь блок try
331
331
blocks .enterBlock ();
332
332
333
- blocks .enterBlock ();
334
- ctx .exceptCodeBlock ().accept (this );
335
- var exception = blocks .leaveBlock ();
333
+ StatementsBlockWriter .StatementsBlockRecord exception ;
334
+ CfgVertex exceptionHandler ;
335
+
336
+ // Check if except block exists before processing it
337
+ if (ctx .exceptCodeBlock () != null ) {
338
+ blocks .enterBlock ();
339
+ ctx .exceptCodeBlock ().accept (this );
340
+ exception = blocks .leaveBlock ();
341
+ exceptionHandler = exception .begin ();
342
+ } else {
343
+ // If no except block, use the parent's exception handler
344
+ exceptionHandler = blocks .getCurrentBlock ().getJumpContext ().exceptionHandler ;
345
+ exception = null ;
346
+ }
336
347
337
348
var jumpInfo = new StatementsBlockWriter .JumpInformationRecord ();
338
- jumpInfo .exceptionHandler = exception . begin () ;
349
+ jumpInfo .exceptionHandler = exceptionHandler ;
339
350
340
351
blocks .enterBlock (jumpInfo );
341
352
ctx .tryCodeBlock ().accept (this );
@@ -344,8 +355,13 @@ public ParseTree visitTryStatement(BSLParser.TryStatementContext ctx) {
344
355
graph .addEdge (tryBranch , success .begin (), CfgEdgeType .TRUE_BRANCH );
345
356
blocks .getCurrentBlock ().getBuildParts ().push (success .end ());
346
357
347
- graph .addEdge (tryBranch , exception .begin (), CfgEdgeType .FALSE_BRANCH );
348
- blocks .getCurrentBlock ().getBuildParts ().push (exception .end ());
358
+ if (exception != null ) {
359
+ graph .addEdge (tryBranch , exception .begin (), CfgEdgeType .FALSE_BRANCH );
360
+ blocks .getCurrentBlock ().getBuildParts ().push (exception .end ());
361
+ } else {
362
+ // If no except block, connect false branch to the parent's exception handler
363
+ graph .addEdge (tryBranch , exceptionHandler , CfgEdgeType .FALSE_BRANCH );
364
+ }
349
365
350
366
var builtBlock = blocks .leaveBlock ();
351
367
0 commit comments