Why does this catch NOT work?

Try
  Dim pic As New Picture(20000, 20000, 32)
  [b]Catch err As OutOfMemoryException[/b]
  MsgBox "Insufficient memory to draw the picture!"
  Quit
End Try

Perhaps it manifests as a different kind of exception?
Or uses so much that the whole program dies… :wink:

Try taking out the err As OutOfMemoryException and see what happens…

Thank you, Jeff. I took out “err As OutOfMemoryException”, XOJO still shows “An exception of class OutOfMemoryException was not handled. The application must shut down.”

you can’t allocate 3.2 GB in a 32bit app.
This must fail.

To Christian: How do I catch this error? Thanks!

check the total size size before trying to do it
(height * width * depth) / (1024 * 1024) = how many Mb you’re trying to allocate
if that is > 3000 then fail BEFORE trying to do it

Actually I just tried it. It does not fail here for the first picture in a fresh started app.

For second image the catch above should catch the exception.

you may also see OutOfBounds exceptions with message:

Width/Height needs to be in the range 1-32767

if your width/height are too big.

[quote=242665:@Christian Schmitz]you may also see OutOfBounds exceptions with message:
Width/Height needs to be in the range 1-32767
if your width/height are too big.[/quote]
That message is is the IDE doing exactly what I suggested - checking the size before trying to allocate a gigantic picture :slight_smile:

Are you seeing this in the IDE? or a compiled application?

If it is in the IDE do you have BREAK ON EXCEPTIONS checked? If so, I believe that trumps TRY/CATCH in the IDE