Exemplo n.º 1
0
        /// <summary>
        /// Execute code safely using the Iodine engine.
        /// </summary>
        /// <returns>The iodine operation.</returns>
        /// <param name="instance">Instance.</param>
        /// <param name="action">Action.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        static T WrapIodineOperation <T> (Shell instance, Func <T> action) where T : IodineObject
        {
            try {
                // Try to just run the specified operation
                return(action());
            } catch (Iodine.Compiler.SyntaxException e) {
                // Handle exception
                IodineExceptionHandler.HandleSyntaxException(instance, e);
            } catch (UnhandledIodineExceptionException e) {
                // Handle exception
                IodineExceptionHandler.HandleUnhandledIodineException(instance, e);
            } catch (ModuleNotFoundException e) {
                // Handle exception
                IodineExceptionHandler.HandleModuleNotFoundException(instance, e);
            } catch (Exception e) {
                // The Iodine engine exploded and we have no idea why.
                // Show the error to the user, maybe he can do something useful with it.
                Console.WriteLine(e.Message);
            }

            // Nothing to do here
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Run a syntax check only.
        /// </summary>
        void RunCheck()
        {
            // Get the file
            var content = string.Empty;

            try {
                content = File.ReadAllText(Conf.File);
            } catch (FileNotFoundException ex) {
                ANSI.WriteLine(ex.Message);
                Environment.Exit(1);
            }

            // Compile the module
            Iodine.Engine.Context.ShouldCache = false;
            try {
                Iodine.CompileSource(content);
                ANSI.WriteLine("OK - No syntax errors.");
            } catch (Iodine.Compiler.SyntaxException e) {
                ANSI.WriteLine($"ERR - Syntax errors occurred.\n");
                IodineExceptionHandler.HandleSyntaxException(this, e);
            } catch (Exception e) {
                ANSI.WriteLine($"ERR - {e.Message}");
            }
        }