diff --git a/src/_tkagg.cpp b/src/_tkagg.cpp index 431465ca3348..1d690f4f4e00 100644 --- a/src/_tkagg.cpp +++ b/src/_tkagg.cpp @@ -111,8 +111,10 @@ static int PyAggImagePhoto(ClientData clientdata, Tcl_Interp *interp, int destheight = (int)(y2 - y1); deststride = 4 * destwidth; - destbuffer = new agg::int8u[deststride * destheight]; - if (destbuffer == NULL) { + try { + destbuffer = new agg::int8u[deststride * destheight]; + } + catch (std::bad_alloc) { TCL_APPEND_RESULT(interp, "could not allocate memory", (char *)NULL); return TCL_ERROR; }