Writing SEH translator

class seh_exception : public std::exception {
public:   
    seh_exception(UINT se_code, PEXCEPTION_POINTERS se_info);
    seh_exception(const seh_exception& old);
    ~seh_exception();

    const char *what() const;
};

void translate_seh_exception(UINT se_code, PEXCEPTION_POINTERS se_info) {
    throw seh_exception(se_code, se_info);
}

Now, what do I do in the constructor? I couldn't find any information on how long *se_info will exist, which means that I probably shouldn't just save se_info in a private field for later use — I should deeply copy it. Or maybe not?

And what's with what()? Am I supposed to conjure the underlying string on-demand? Again, allocating memory in the constructor seems not a very good idea in this case.

I've currently implemented it storing se_code and se_info without any deep-copying, and generating formatted message in the constructor, and it works, though I do not know if it is actually supposed to work.

I intend to use it in "catch, log what happened, terminate" scenario.

Answers


You don't need your own class just to achieve this, you can just throw the PEXCEPTION_POINTERS. se_code is also available at se_info->ExceptionRecord->ExceptionCode.

So the simplest handler is just;

void translate_seh_exception(UINT se_code, PEXCEPTION_POINTERS se_info) {
    throw se_info;
}

You can then catch(PEXCEPTION_POINTERS se_info)

The EXCEPTION_POINTERS is guaranteed to exist for the duration of the catch block, which is how long you need it for. As per the documentation, your translator function is called once for each catch block, that is, it has to re-translate the SEH exception for every function containing a try/catch block.


Need Your Help

Self-signed java applet raise error "Permission denied" while send mail via SMTP

java email applet smtp socketexception

I have self-signed java applet. This applet should send email message every time, when raise unhandled exception.

Whois list of Top Level Domain against their corresponding registrar

whois tld

I'm trying to find a list of TLD's to their corresponding whois server, for example