kwenyao
kwenyao

Reputation: 67

Is it possible to catch an exception in another .cpp or .h file?

I am trying to create a program using windows form in c++ and i am wondering if i can throw an exception in logic.cpp and catch it with my ui.cpp

Upvotes: 1

Views: 584

Answers (2)

detunized
detunized

Reputation: 15289

You can catch an exception that was thrown anywhere down the callstack. If the function in ui.cpp calls the function in logic.cpp that throws the exception then yes, you can catch it.

Upvotes: 5

Mark B
Mark B

Reputation: 96241

You can do this. But you need to make sure that the respective source files are compiled with the same settings and defines (and likely other things) to make sure that the exception API/ABI doesn't differ between compilation units.

Upvotes: 1

Related Questions