You didn't understand. converting the exception isn't the issue....and you can 
certainly throw exceptions in catch blocks.

The original email was itself an explanation of the problem. Let me provide a 
concrete example...       


    public static DbException convert(Throwable e) {
        if (e instanceof DbException) {
            return (DbException) e;
        } else if (e instanceof SQLException) {
            return new DbException((SQLException) e);   <<-----  problem here.




I'm not exactly where what the java new operator does when the memory can't be 
allocated, but in C++, the new operator can throw std::bad_alloc in that case. 
Therefore, a simple-mindled translation of this code to C++ would set up a 
situation where another exception can be thrown while handling an exception. 
Therefore, one generally avoids allocating heap memory or doing anything else 
that could throw an exception while handling an exception. Also, throwing 
pointers to exceptions is avoided in C++ because there is no mechanism to guard 
the pointer to the exception and make sure it gets released.


http://www.cplusplus.com/reference/std/new/bad_alloc/


a good reference on best practices in C++ would be scott meyers' books:

Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd 
Edition)
More Effective C++: 35 New Ways to Improve Your Programs and Designs



Because I can make meaningful recommendations on what needs to be done, I need 
to spend more time studying the system to see what the requirements are. 
However, as a basic, high-level goal... functions that handle exceptions should 
be no-throw except to convert an exception to an intended exception. In C++, 
orthodox practice is to throw by value and catch by reference.


On Apr 17, 2010, at 10:14 AM, Thomas Mueller wrote:

> Hi,
> 
> I'm not an expert in C++, but I guess it's legal to throw an exception
> in the catch block. Is it not? If not, could you provide a link?
> 
>> The reason this code is not proper
>> form (aside from the fact that you are throwing a pointer)
> 
> I don't understand. Could you provide a link? I read it's OK to throw
> Objects in C++ (that's what Java does):
> http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.6
> 
>> So, right in the middle of handling
>> an exception, you can cause a new exception to be thrown that masks the
>> actual exception.
> 
> It's not masking, it's converting (to / from RuntimeException). There
> are no checked exceptions in C++, so this might not be required.
> 
>> standard practice in C++ is to throw classes and
>> catch references to classes.
> 
> Could you provide a link?
> 
>> Is redesigning the exception handling to flatten it out and make it all
>> guaranteed no-throw a goal you'd be interested in?
> 
> I'm not sure. What do you have in mind?
> 
> Regards,
> Thomas
> 
> -- 
> You received this message because you are subscribed to the Google Groups "H2 
> Database" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/h2-database?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to