Handle error with try catch blocks system() #12916

Closed
opened 2026-01-31 03:28:52 +00:00 by claunia · 2 comments
Owner

Originally created by @Goru1890 on GitHub (Mar 8, 2021).

Does anyone know how I can handle system() errors with try catch in C++ ?
I want to throw an excepctions when a error ocurres in the terminal, like Cuda Out of Memory or something else
Now I have this, but of course it's stucked in the system() line

Originally created by @Goru1890 on GitHub (Mar 8, 2021). Does anyone know how I can handle system() errors with try catch in C++ ? I want to throw an excepctions when a error ocurres in the terminal, like Cuda Out of Memory or something else Now I have this, but of course it's stucked in the system() line ![](https://cdn.discordapp.com/attachments/787383971012411414/818418846222254100/unknown.png) ![](https://cdn.discordapp.com/attachments/787383971012411414/818418928119185418/unknown.png)
claunia added the Issue-QuestionNeeds-TriageNeeds-Tag-Fix labels 2026-01-31 03:28:52 +00:00
Author
Owner

@KalleOlaviNiemitalo commented on GitHub (Mar 8, 2021):

If the system function detects the error, then it returns -1 and sets errno; so you should check the return value. However, the program that system runs may fail in ways that system does not detect.

None of this seems specific to Windows Terminal, though.

@KalleOlaviNiemitalo commented on GitHub (Mar 8, 2021): If the [system](https://docs.microsoft.com/cpp/c-runtime-library/reference/system-wsystem?view=msvc-160) function detects the error, then it returns -1 and sets `errno`; so you should check the return value. However, the program that `system` runs may fail in ways that `system` does not detect. None of this seems specific to Windows Terminal, though.
Author
Owner

@zadjii-msft commented on GitHub (Mar 8, 2021):

Yea, this isn't really a Terminal-specific issue. This almost seems like a question better suited for StackOverflow.

Thanks!

@zadjii-msft commented on GitHub (Mar 8, 2021): Yea, this isn't really a Terminal-specific issue. This almost seems like a question better suited for StackOverflow. Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12916