Kira
Kira

Reputation: 1207

Using Try/Catch with naked functions

Why using Try-Catch is not allowed with naked functions? And is there an alternative?

Error 2 error C2490: 'try' not allowed in function with 'naked' attribute   

Upvotes: 1

Views: 251

Answers (2)

Mats Petersson
Mats Petersson

Reputation: 129444

The reason it doesn't work to use exception handling over "naked" is that they functions don't have the standard prolog and epilog parts, which is necessary for "unwinding of the stack", which "catch" does. It says so here (limitations of naked functions).

You will need to find some other way to achieve what you want - either wrap your naked functions some way that "makes them dressed"[dressed = opposite of naked, not sure if that is the technical term] or don't use try-catch.

Upvotes: 2

Component 10
Component 10

Reputation: 10497

Structured Exception Handling and C++ Exception Handling constructs are not permitted because they must unwind across the stack frame.

(see this link from the same site as above)

Upvotes: 4

Related Questions