PrevUpHomeNext

utxcpp::main


utxcpp::main main entry point

utxcpp c++ utxcpp::main main entry point.

utxcpp::main Hello World

Return 0 by default,

#include <utxcpp/main.hpp>

void utxcpp::main()
{
	std::cout << "Hello ";
	utx::print("World");
}	// return 0 by default

include utxcpp/main.cpp implies include these headers:

self.set_return(value)

The return value of main is set by self.set_return(value), not by return statement.

#include <utxcpp/main.hpp>

void utxcpp::main()
{
	std::cout << "set return value to 123" <<std::endl;
	self.set_return(123);
}	// return value is set to 123

catch exception by default

The main exception will be caught by default, this can make some levels of lazy.

#include <utxcpp/main.hpp>

void utxcpp::main()
{
	std::error_code ec;
	throw std::system_error{ec, "Test c++ exception"};
}	// exception will be caught and handled even if you do not write try...catch... block.

output:

[c++ main exception] [std::exception] in main:
        Test c++ exception: Success

self.enable_tcrash(true/false)

#include <utxcpp/main.hpp>

void utxcpp::main()
{
	self.enable_tcrash(true);
	throw std::runtime_error{"c++ standard exception"};
}

After self.enable_tcrash(true); (it is false by default), throw exception will be played as "pseudo crash" .

output:

terminate called after throwing an instance of 'std::runtime_error'
  what():  [c++ main exception] [std::exception] in main:
       c++ standard exception
Aborted

argc argv

argc and argv are stored in args, that its type is std::vector<std::string>,

argc is the vector size, each argv is std::string type.

#include <utxcpp/main.hpp>

void utxcpp::main()
{
	std::cout << "argc-> " << args.size() << std::endl;
	
	std::cout << "argv:\n";
	for (const std::string_view arg: args)
		std::cout << "\t" << arg << std::endl;
}

./main5 ls pwd whoami

output:

argc-> 4
argv:
	./main5
	ls
	pwd
	whoami

See Also

utx::print

utx::printnl


PrevUpHomeNext

utx::print

esv::print