Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, October 2008
QByteArray::resize : what happens in failure


Message 1 in thread

A short and simple question.

How an application can detect failure in 
	QByteArray::resize(int newSize)
method, since resize() is a void function?

Thanks in advance!

--
 [ signature omitted ] 

Message 2 in thread

On Monday 06 October 2008 09:33:04 Taipale, Eero wrote:
> A short and simple question.
>
> How an application can detect failure in
> 	QByteArray::resize(int newSize)
> method, since resize() is a void function?

You can't.

If memory allocation fails, you're out of luck. You should crash your 
application at this point and help the system free up memory for other 
applications.

Qt, in general, does not check for out-of-resource conditions (out of memory, 
out of file descriptors, etc.)

We've been considering throwing exceptions when that happens, just so that you 
may try and save important stuff. But the error is non-recoverable, since most 
Qt codepaths aren't exception-safe either.

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 3 in thread

Am Montag, 6. Oktober 2008 schrieb Taipale, Eero:
> A short and simple question.
> How an application can detect failure in
> 	QByteArray::resize(int newSize)
> method, since resize() is a void function?
> Thanks in advance!

When you are out of memory (yes that still happens in times of 8+GB ram:), the 
underlying allocation-system throws an exception. Qt doesn't handle 
exceptions and complains when it catches one inside the event-loop. But if 
you know that you might be low on memory and such calls as above might fail, 
you can always catch these exceptions before Qt sees them.

Have fun,

Arnold
-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 4 in thread

Arnold Krille wrote:

> you know that you might be low on memory and such calls as above might
> fail, you can always catch these exceptions before Qt sees them.
If the exception is thrown inside a QByteArray::resize() call, Qt will 'see'
it. And if that codepath (within Qt) happens not to be exception safe, then
it might be too late to fix the problem at the call site of
QByteArray::resize().

--
 [ signature omitted ]