On 15/02/2010 21:54, Mark Grice wrote:
I am using IronPython within a C# .NET application.

I have a class that the Python code uses, so I create a scope and set the variable, then execute the engine like this:

        private ScriptEngine scptEngine = null;
        private ScriptRuntime scptRuntime = null;
        private ScriptScope scptScope;
        private ScriptSource scptSource;

        public pyEngine()
        {
                scptEngine = Python.CreateEngine();
                scptRuntime = scptEngine.Runtime;
                scptScope = scptEngine.CreateScope();
                AddAssemblies(scptRuntime);
                SOA SOA_screen = new SOA();                 // my Class
                scptScope.SetVariable("screen", SOA_screen);
scptSource = scptEngine.CreateScriptSourceFromFile(scriptFile);
                scptSource.Execute(scptScope);
         }

This runs fine. But within the Python code, if I detect an error, I want to exit out of scriptFile.

I check a flag and try to exit if flag is false: so, the basic python is:

   if MessageScreenIsActive == False :
      screen.Say("CAN NOT PROCEED: " + screen.lastResultMessage);
      sys.exit()

This throws an exception.
That will throw a SystemExit exception. You can have exception handling in your C# that catches this specific error.

But this:

   if MessageScreenIsActive == False :
      screen.Say("CAN NOT PROCEED: " + screen.lastResultMessage);
      sys.exit
You're not actually calling sys.exit here...


All the best,

Michael

only exits the <IF block> -- not the whole script.

Of course, I can bracket off all of my code with if/else and control it this way, but there must be a simple way to simple exit the script... isn't there?

Thanks for reading!



_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your 
employer, to release me from all obligations and waivers arising from any and all 
NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, 
confidentiality, non-disclosure, non-compete and acceptable use policies ("BOGUS 
AGREEMENTS") that I have entered into with your employer, its partners, licensors, 
agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. 
You further represent that you have the authority to release me from any BOGUS AGREEMENTS 
on behalf of your employer.


_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to