Skip to main content
gamedev.net
🔒 Locked

Forcing Exception Handling

Started by gommo 0 replies 250+ views
Original Post
gommo
gommo
In c++ can you right exception throwing functions (in classes) that force users of the class to us try catch clauses, like in Java. Its just that I throw an exception from my main engine class if there is an error initialising the specific renderer (depending on API) but i can still instantiate the engine by doing this CHooge* m_pEngine = new CHoogeEngine(); instead of this try { CHoogeEngine* m_pEngine = new CHoogeEngine(); } catch(CHoogeEngine e) { //stugg } Thanks P.S. Whats the best way to catch thrown exceptions that are classes. By value or by reference??
JuNC
JuNC
You should catch by reference.

I don''t think theres any way of ''forcing'' client code to catch the exception, but it will propagate upwards even without a try{}catch{} block so it will be caught at some point, even if it is the program exiting.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.