juanmanzanero / fastest-lap

Fastest-lap is a vehicle dynamics simulator. It can be used to understand vehicle dynamics, to learn about driving techniques, to design car prototypes, or just for fun!
MIT License
575 stars 43 forks source link

Windows: thrown exceptions error message is missing. #22

Closed juanmanzanero closed 2 years ago

juanmanzanero commented 2 years ago

In windows, the error message is not shown in the python console. It only terminates abruply showing a winError message with gnarly and horrible memory addresses. It seems the error stream does not work properly.

However, the output stream does. So use it to show the error message instead.

The task: add a try-catch block to all the functions of the C library fastestlapc.cpp such as:

void any_function()
{
 try
 {
     // ... all the code ...
 } 
 catch(fastest_lap_exception& ex)
 {
    std::cout << "[Fastest lap exception] -> " << ex.what() << std::endl;
    throw std::runtime_error("Terminate program");
 }
catch(lion_exception& ex)
 {
    std::cout << "[Lion exception] -> " << ex.what() << std::endl;
    throw std::runtime_error("Terminate program");
 } 
 catch(std::exception& ex)
 {
    std::cout << "[C++ exception] -> " << ex.what() << std::endl;
    throw std::runtime_error("Terminate program");
 }
}

All the catch statements must be encapsulated in a #define CATCH macro so that the code is neat

 try
 {
     // ... all the code ...
 } 
CATCH