Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354609 - EGL code has try-block on AnyException but generated Java has unhandled exception
Summary: EGL code has try-block on AnyException but generated Java has unhandled excep...
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: EDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-12 08:22 EDT by Kathy Carroll CLA
Modified: 2017-02-23 14:17 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kathy Carroll CLA 2011-08-12 08:22:31 EDT
Generated Java is getting the error message:
             Unhandled exception type IOException

EGL code:

============

ExternalType File type JavaObject {packageName = "java.io"}
	 constructor (pathname String In);
	 function getAbsolutePath() returns (String);
	 function createNewFile() returns (boolean);
	 function mkdirs() returns (boolean);
	 function exists() returns (boolean);
end

ExternalType FileWriter type JavaObject { packageName = "java.io"}
	constructor (file File In);
	constructor (filename String In);
	function write(str String In);
//	function close_() {javaName ="close"};  //354044 The javaName annotation for external JavaObject functions is missing 
end

ExternalType IOException type JavaObject { packageName = "java.io"}
end
================
handler CreateResultFile 
	function createFile(fileDirectory String in, fullFileName String in, fileContent String in)
		myfile File  = new File(fileDirectory);
		//if(!etrFile.exists())
			createdDirs boolean = myfile.mkdirs();
			if(createdDirs)
				sysLib.writeStdOut("directories created");			
			end					
		//end
		
		outWriter FileWriter;  
		try
			syslib.writeStdOut (myfile.getAbsolutePath());
			
			outWriter = new FileWriter(fullFileName);
			outWriter.write(fileContent);
//			outWriter.close_();
//		onException (ioExp IOException)
//			syslib.writeStdOut("IOException occrred!");
		onException (exp AnyException)
			syslib.writeStdOut("oops can't get to it");
			syslib.writeStdOut("Exception occurred!");
		end
	end	
end

Generated JAVA

		FileWriter outWriter = null;
		try {
			SysLib.writeStdout(myfile.getAbsolutePath());
			outWriter = new FileWriter(fullFileName);
			outWriter.write(fileContent);
		}
		catch (AnyException exp) {
			String eze$Temp3 = Constants.EMPTY_STRING;
			eze$Temp3 = "oops can't get to it";
			SysLib.writeStdout(eze$Temp3);
			String eze$Temp4 = Constants.EMPTY_STRING;
			eze$Temp4 = "Exception occurred!";
			SysLib.writeStdout(eze$Temp4);
		}

No java compile error in RBD for this example
Comment 1 Jeff Douglas CLA 2011-08-12 15:03:00 EDT
The root of this problem is that IOException has not yet been defined in EGL.

This needs to be added to the EGL source files that are generated into the IR logic.
Comment 2 Matt Heitz CLA 2011-08-12 15:15:58 EDT
Actually, the problem is that an onException block catching AnyException needs to be generated differently than other onException blocks.  I'm familiar with this because RBD had to deal with this problem too.

We have to generate a catch for all Exceptions.  If we catch something that's not one of our exceptions, create an AnyException to represent it.

EGL
---
onException (exp AnyException)
  // ...body of the onException block...
end


Generated Java
--------------
catch ( Exception ezeTemp1 )
{
  exp AnyException;
  if ( ezeTemp1 instanceof AnyException )
    exp = (AnyException)ezeTemp1;
  else
    exp = ...some code to make an AnyException from ezeTemp1...

  // ...code for the body of the onException block...
}
Comment 3 Matt Heitz CLA 2011-08-14 11:35:02 EDT
I made the changes in TryStatementTemplate.
Comment 4 Kathy Carroll CLA 2011-08-15 14:33:38 EDT
verified
Comment 5 Lisa Lasher CLA 2011-10-11 16:22:47 EDT
Closing this defect.