--[[
---------------------------------------------------------------------------
Remote Train Control Program for Windows

© Copyright 2019 by Mark DiVecchio

	This file is part of Remote Train Control.

	Remote Train Control is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Remote Train Control is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Remote Train Control.  If not, see <http://www.gnu.org/licenses/>.

 Home Page : http://www.silogic.com/trains/RTC_Running.html
---------------------------------------------------------------------------]]
-- Semicolons are not required in Lua code
title = "Error Test"
require("defines");

--[[---------------------------------------------------------------------------------------]]
function setup(Engine, TIU)
	print(os.date("setup() %d %b %Y   %X"));
	return true;		-- false=setup failed, true=setup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
function loop()
	print("loop()");
	local status, err = pcall(function() error({code=121}) end);
	print("Error Code (should be 121) = ", err.code);	-- Caught error
		
	testvalue = 5;
	n = assert(tonumber(testvalue), "testvalue is not a number");	-- this assert() does not force an error	
	testvalue = "not a number";
	print("Generates an error which terminates loop()");
	n = assert(tonumber(testvalue), "testvalue is not a number");	-- this assert() forces an error

	return Stop("End of Error Test");	-- this line is never reached as assert() forces an uncaught error
	end
--[[---------------------------------------------------------------------------------------]]
function cleanup()
	-- this function is never called but the script terminates on its own
	print(os.date("cleanup()  %d %b %Y   %X"));
	return true;		-- false=cleanup failed, true=cleanup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
