Commits

Boolsheet committed 4397a23

Added an exception handling macro that throws a Lua error with the exception message.
Also, code style enforcing and trimmed trailing space.

  • Participants
  • Parent commits 16bc7c0
  • Branches eh-macro

Comments (0)

Files changed (32)

src/common/Exception.h

 #include <cstring> // strncpy
 #include <string>
 
+#define LOVE_EH_CATCH_AND_ERROR(CODE_BLOCK) try { CODE_BLOCK } catch (love::Exception &e) { return luaL_error(L, "%s", e.what()); }
+
 namespace love
 {
 

src/common/Memoizer.cpp

  *    misrepresented as being the original software.
  * 3. This notice may not be removed or altered from any source distribution.
  **/
- 
+
 #include "Memoizer.h"
 #include <cstddef>
 

src/modules/audio/wrap_Audio.cpp

 		{
 			instance = new love::audio::openal::Audio();
 		}
-		catch(love::Exception &e)
+		catch (love::Exception &e)
 		{
 			std::cout << e.what() << std::endl;
 		}
 		{
 			instance = new love::audio::null::Audio();
 		}
-		catch(love::Exception &e)
+		catch (love::Exception &e)
 		{
 			std::cout << e.what() << std::endl;
 		}

src/modules/event/sdl/wrap_Event.cpp

 {
 	if (instance == 0)
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			instance = new Event();
-		}
-		catch(Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 		instance->retain();

src/modules/filesystem/physfs/Filesystem.cpp

 			{
 				str = new char[linesize + 1];
 			}
-			catch(std::bad_alloc &)
+			catch (std::bad_alloc &)
 			{
 				return luaL_error(L, "Out of memory");
 			}

src/modules/filesystem/physfs/wrap_File.cpp

 	if (!File::getConstant(luaL_checkstring(L, 2), mode))
 		return luaL_error(L, "Incorrect file open mode: %s", luaL_checkstring(L, 2));
 
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		lua_pushboolean(L, file->open(mode) ? 1 : 0);
-	}
-	catch(Exception e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 
 	return 1;
 }
 
 	int64 size = (int64)luaL_optnumber(L, 2, (lua_Number) file->getSize());
 
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		d = file->read(size);
-	}
-	catch(Exception e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 
 	lua_pushlstring(L, (const char *) d->getData(), d->getSize());
 	lua_pushnumber(L, d->getSize());
 		return luaL_error(L, "File is not open.");
 	if (lua_isstring(L, 2))
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			result = file->write(lua_tostring(L, 2), luaL_optint(L, 3, lua_objlen(L, 2)));
-		}
-		catch(Exception e)
-		{
-			return luaL_error(L, e.what());
-		}
-
+		)
 	}
 	else if (luax_istype(L, 2, DATA_T))
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			love::Data *data = luax_totype<love::Data>(L, 2, "Data", DATA_T);
 			result = file->write(data, luaL_optint(L, 3, data->getSize()));
-		}
-		catch(Exception e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 	{
 		if (file->getMode() != File::CLOSED)
 			file->close();
 
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			if (!file->open(File::READ))
 				return luaL_error(L, "Could not open file.");
-		}
-		catch(love::Exception &e)
-		{
-			return luaL_error(L, "%s", e.what());
-		}
+		)
 	}
 
 	lua_pushcclosure(L, Filesystem::lines_i, 3);

src/modules/filesystem/physfs/wrap_Filesystem.cpp

 int w_init(lua_State *L)
 {
 	const char *arg0 = luaL_checkstring(L, 1);
-
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		instance->init(arg0);
-	}
-	catch(Exception &e)
-	{
-		return luaL_error(L, e.what());
-	}
-
+	)
 	return 0;
 }
 
 {
 	const char *filename = luaL_checkstring(L, 1);
 	File *t;
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		t = instance->newFile(filename);
-	}
-	catch(Exception e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 	luax_newtype(L, "File", FILESYSTEM_FILE_T, (void *)t);
 	return 1;
 }
 
 int w_read(lua_State *L)
 {
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		return instance->read(L);
-	}
-	catch(Exception e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 }
 
 int w_write(lua_State *L)
 {
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		return instance->write(L);
-	}
-	catch(Exception e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 }
 
 int w_enumerate(lua_State *L)
 	if (lua_isstring(L, 1))
 	{
 		file = instance->newFile(lua_tostring(L, 1));
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			if (!file->open(File::READ))
 				return luaL_error(L, "Could not open file.");
-		}
-		catch(love::Exception &e)
-		{
-			return luaL_error(L, "%s", e.what());
-		}
+		)
 		luax_newtype(L, "File", FILESYSTEM_FILE_T, file);
 	}
 	else
 
 int w_load(lua_State *L)
 {
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		return instance->load(L);
-	}
-	catch(love::Exception &e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 }
 
 int w_getLastModified(lua_State *L)
 {
 	if (instance == 0)
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			instance = new Filesystem();
 			love::luax_register_searcher(L, loader, 1);
 			love::luax_register_searcher(L, extloader, 2);
-		}
-		catch(Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 	{

src/modules/font/freetype/wrap_Font.cpp

 {
 	if (instance == 0)
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			instance = new Font();
-		}
-		catch(Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 		instance->retain();

src/modules/graphics/opengl/Font.cpp

 			dx += glyph->spacing + letter_spacing;
 		}
 	}
-	catch(utf8::exception &e)
+	catch (utf8::exception &e)
 	{
 		glPopMatrix();
 		throw love::Exception("%s", e.what());
 				if (!g) g = addGlyph(c);
 				width += static_cast<int>(g->spacing * mSpacing);
 			}
+
 		}
-		catch(utf8::exception &e)
+		catch (utf8::exception &e)
 		{
 			throw love::Exception("%s", e.what());
 		}

src/modules/graphics/opengl/Graphics.cpp

 	{
 		success = image->load();
 	}
-	catch(love::Exception &e)
+	catch (love::Exception &e)
 	{
 		image->release();
 		throw love::Exception(e.what());
 	{
 		t = new SpriteBatch(image, size, usage);
 	}
-	catch(love::Exception &e)
+	catch (love::Exception &e)
 	{
 		if (t) delete t;
 		throw e;
 	{
 		effect = new PixelEffect(code);
 	}
-	catch(love::Exception &e)
+	catch (love::Exception &e)
 	{
 		if (effect)
 			delete effect;

src/modules/graphics/opengl/ParticleSystem.cpp

 
 	if (pStart != 0)
 		delete [] pStart;
-	
+
 	if (particleVerts != 0)
 		delete [] particleVerts;
 }
 	pLast = pStart = new particle[size];
 
 	pEnd = pStart + size;
-	
+
 	if (particleVerts != 0)
 		delete [] particleVerts;
-	
+
 	// each particle has 4 vertices
 	particleVerts = new vertex[size*4];
 }
 void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
 {
 	if (sprite == 0) return;  // just in case of failure
-	
+
 	int numParticles = count();
 	if (numParticles == 0) return; // don't bother if there's nothing to do
 
 	static Matrix t;
 	t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
 	glMultMatrixf((const GLfloat *)t.getElements());
-	
+
 	const vertex * imageVerts = sprite->getVertices();
-	
+
 	// set the vertex data for each particle (transformation, texcoords, color)
 	for (int i = 0; i < numParticles; i++)
 	{
 		particle * p = pStart + i;
-		
-		// particle vertices are sprite vertices transformed by particle information 
+
+		// particle vertices are sprite vertices transformed by particle information
 		t.setTransformation(p->position[0], p->position[1], p->rotation, p->size, p->size, offsetX, offsetY, 0.0f, 0.0f);
 		t.transform(&particleVerts[i*4], &imageVerts[0], 4);
-		
+
 		// set the texture coordinate and color data for particle vertices
 		for (int v = 0; v < 4; v++) {
 			int vi = (i * 4) + v; // current vertex index for particle
-			
+
 			particleVerts[vi].s = imageVerts[v].s;
 			particleVerts[vi].t = imageVerts[v].t;
-			
+
 			// particle colors are stored as floats (0-1) but vertex colors are stored as unsigned bytes (0-255)
 			particleVerts[vi].r = p->color.r*255;
 			particleVerts[vi].g = p->color.g*255;
 			particleVerts[vi].a = p->color.a*255;
 		}
 	}
-	
+
 	sprite->bind();
-	
+
 	glEnableClientState(GL_COLOR_ARRAY);
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-	
+
 	glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid *)&particleVerts[0].r);
 	glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&particleVerts[0].x);
 	glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&particleVerts[0].s);
-	
+
 	glDrawArrays(GL_QUADS, 0, numParticles*4);
-	
+
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_COLOR_ARRAY);

src/modules/graphics/opengl/ParticleSystem.h

 
 	// Pointer to the end of the memory allocation.
 	particle *pEnd;
-	
+
 	// array of transformed vertex data for all particles, for drawing
 	vertex * particleVerts;
 

src/modules/graphics/opengl/VertexBuffer.cpp

 		// Try to create a VBO.
 		return new VBO(size, target, usage);
 	}
-	catch(const love::Exception &)
+	catch (const love::Exception &)
 	{
 		// VBO not supported ... create regular array.
 		return new VertexArray(size, target, usage);

src/modules/graphics/opengl/wrap_Font.cpp

 {
 	Font *t = luax_checkfont(L, 1);
 	const char *str = luaL_checkstring(L, 2);
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		lua_pushinteger(L, t->getWidth(str));
-	}
-	catch(love::Exception &e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 	return 1;
 }
 
 	const char *str = luaL_checkstring(L, 2);
 	float wrap = (float) luaL_checknumber(L, 3);
 	int max_width = 0, numlines = 0;
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		std::vector<std::string> lines = t->getWrap(str, wrap, &max_width);
 		numlines = lines.size();
-	}
-	catch(love::Exception &e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 	lua_pushinteger(L, max_width);
 	lua_pushinteger(L, numlines);
 	return 2;

src/modules/graphics/opengl/wrap_Graphics.cpp

 
 	// Create the image.
 	Image *image = 0;
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		image = instance->newImage(data);
-	}
-	catch(love::Exception &e)
-	{
-		luaL_error(L, e.what());
-	}
+	)
 
 	if (image == 0)
 		return luaL_error(L, "Could not load image.");
 	if (luax_istype(L, 1, FILESYSTEM_FILE_T))
 	{
 		love::filesystem::File *f = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			font_data = f->read();
-		}
-		catch(love::Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 		lua_remove(L, 1); // get rid of the file
 		luax_newtype(L, "Data", DATA_T, (void *)font_data);
 		lua_insert(L, 1); // put it at the bottom of the stack
 			usage = SpriteBatch::USAGE_DYNAMIC;
 	}
 	SpriteBatch *t = NULL;
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		t = instance->newSpriteBatch(image, size, usage);
-	}
-	catch(love::Exception &e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 	luax_newtype(L, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T, (void *)t);
 	return 1;
 }
 		return luaL_error(L, "Invalid canvas type: %s", str);
 
 	Canvas *canvas = NULL;
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		canvas = instance->newCanvas(width, height, texture_type);
-	}
-	catch(Exception &e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 
 	if (NULL == canvas)
 		return luaL_error(L, "Canvas not created, but no error thrown. I don't even...");
 		PixelEffect *effect = instance->newPixelEffect(code);
 		luax_newtype(L, "PixelEffect", GRAPHICS_PIXELEFFECT_T, (void *)effect);
 	}
-	catch(const love::Exception &e)
+	catch (const love::Exception &e)
 	{
 		// memory is freed in Graphics::newPixelEffect
 		luax_getfunction(L, "graphics", "_transformGLSLErrorMessages");
 	if (!Graphics::getConstant(str, mode))
 		return luaL_error(L, "Invalid blend mode: %s", str);
 
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		instance->setBlendMode(mode);
-	}
-	catch(love::Exception &e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 	return 0;
 }
 
 	{
 		instance->print(str, x, y, angle, sx, sy, ox, oy, kx,ky);
 	}
-	catch(love::Exception e)
+	catch (love::Exception &e)
 	{
 		return luaL_error(L, "Decoding error: %s", e.what());
 	}
 	{
 		instance->printf(str, x, y, wrap, align);
 	}
-	catch(love::Exception e)
+	catch (love::Exception &e)
 	{
 		return luaL_error(L, "Decoding error: %s", e.what());
 	}
 
 int w_push(lua_State *L)
 {
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		instance->push();
-	}
-	catch(love::Exception e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 	return 0;
 }
 
 int w_pop(lua_State *L)
 {
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		instance->pop();
-	}
-	catch(love::Exception e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 	return 0;
 }
 
 {
 	if (instance == 0)
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			instance = new Graphics();
-		}
-		catch(Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 		instance->retain();

src/modules/graphics/opengl/wrap_PixelEffect.cpp

 	{
 		effect->sendFloat(name, 1, values, count);
 	}
-	catch(love::Exception &e)
+	catch (love::Exception &e)
 	{
 		delete[] values;
 		return luaL_error(L, e.what());
 	{
 		effect->sendFloat(name, dimension, values, count);
 	}
-	catch(love::Exception &e)
+	catch (love::Exception &e)
 	{
 		delete[] values;
 		return luaL_error(L, e.what());
 	{
 		effect->sendMatrix(name, dimension, values, count);
 	}
-	catch(love::Exception &e)
+	catch (love::Exception &e)
 	{
 		delete[] values;
 		return luaL_error(L, e.what());
 	const char *name = luaL_checkstring(L, 2);
 	Image *img = luax_checkimage(L, 3);
 
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		effect->sendImage(name, *img);
-	}
-	catch(love::Exception &e)
-	{
-		luaL_error(L, e.what());
-	}
+	)
 
 	return 0;
 }
 	const char *name = luaL_checkstring(L, 2);
 	Canvas *canvas = luax_checkcanvas(L, 3);
 
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		effect->sendCanvas(name, *canvas);
-	}
-	catch(love::Exception &e)
-	{
-		luaL_error(L, e.what());
-	}
+	)
 
 	return 0;
 }

src/modules/graphics/opengl/wrap_SpriteBatch.cpp

 int w_SpriteBatch_bind(lua_State *L)
 {
 	SpriteBatch *t = luax_checkspritebatch(L, 1);
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		t->lock();
-	}
-	catch (love::Exception &e)
-	{
-		return luaL_error(L, "%s", e.what());
-	}
+	)
 	return 0;
 }
 

src/modules/image/devil/ImageData.cpp

 	{
 		this->data = new unsigned char[width*height*sizeof(pixel)];
 	}
-	catch(std::bad_alloc &)
+	catch (std::bad_alloc &)
 	{
 		throw love::Exception("Out of memory");
 	}
 
 		create(width, height, ilGetData());
 	}
-	catch(std::exception &)
+	catch (std::exception &)
 	{
 		ilDeleteImages(1, &image);
 		throw;
 		{
 			encoded_data = new ILubyte[size];
 		}
-		catch(std::bad_alloc &)
+		catch (std::bad_alloc &)
 		{
 			throw love::Exception("Out of memory");
 		}
 		f->write(encoded_data, size);
 		f->close();
 	}
-	catch(std::exception &)
+	catch (std::exception &)
 	{
 		ilDeleteImages(1, &tempimage);
 		delete[] encoded_data;

src/modules/image/wrap_Image.cpp

 			return luaL_error(L, "Invalid image size.");
 
 		ImageData *t = 0;
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			t = instance->newImageData(w, h);
-		}
-		catch(love::Exception &e)
-		{
-			return luaL_error(L, "%s", e.what());
-		}
+		)
 		luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)t);
 		return 1;
 	}
 	{
 		Data *d = luax_checktype<Data>(L, 1, "Data", DATA_T);
 		ImageData *t = 0;
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			t = instance->newImageData(d);
-		}
-		catch(love::Exception &e)
-		{
-			return luaL_error(L, "%s", e.what());
-		}
+		)
 		luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)t);
 		return 1;
 	}
 	love::filesystem::File *file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
 
 	ImageData *t = 0;
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		t = instance->newImageData(file);
-	}
-	catch(love::Exception &e)
-	{
-		return luaL_error(L, "%s", e.what());
-	}
+	)
 	luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)t);
 	return 1;
 }
 {
 	if (instance == 0)
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			instance = new love::image::devil::Image();
-		}
-		catch(Exception &e)
-		{
-			return luaL_error(L, "%s", e.what());
-		}
+		)
 	}
 	else
 		instance->retain();

src/modules/image/wrap_ImageData.cpp

 	int x = luaL_checkint(L, 2);
 	int y = luaL_checkint(L, 3);
 	pixel c;
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		c = t->getPixel(x, y);
-	}
-	catch(love::Exception &e)
-	{
-		return luaL_error(L, "%s", e.what());
-	}
+	)
 	lua_pushnumber(L, c.r);
 	lua_pushnumber(L, c.g);
 	lua_pushnumber(L, c.b);
 	c.g = luaL_checkint(L, 5);
 	c.b = luaL_checkint(L, 6);
 	c.a = luaL_checkint(L, 7);
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		t->setPixel(x, y, c);
-	}
-	catch(love::Exception &e)
-	{
-		return luaL_error(L, "%s", e.what());
-	}
+	)
 	return 0;
 }
 
 			luaL_error(L, "Invalid image format.");
 	}
 
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		t->encode(file, format);
-	}
-	catch(love::Exception &e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 	return 0;
 }
 

src/modules/joystick/sdl/wrap_Joystick.cpp

 
 int w_reload(lua_State *L)
 {
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		instance->reload();
-	}
-	catch(love::Exception &e)
-	{
-		return luaL_error(L, "%s", e.what());
-	}
+	)
 	return 0;
 }
 
 {
 	if (instance == 0)
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			instance = new Joystick();
-		}
-		catch(Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 		instance->retain();

src/modules/keyboard/wrap_Keyboard.cpp

 {
 	if (instance == 0)
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			instance = new love::keyboard::sdl::Keyboard();
-		}
-		catch(Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 		instance->retain();

src/modules/mouse/wrap_Mouse.cpp

 {
 	if (instance == 0)
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			instance = new love::mouse::sdl::Mouse();
-		}
-		catch(Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 		instance->retain();

src/modules/physics/box2d/Physics.cpp

 	b2DistanceOutput o;
 	b2SimplexCache c;
 	c.count = 0;
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		pA.Set(fixtureA->fixture->GetShape(), 0);
 		pB.Set(fixtureB->fixture->GetShape(), 0);
 		i.proxyA = pA;
 		i.transformB = fixtureB->fixture->GetBody()->GetTransform();
 		i.useRadii = true;
 		b2Distance(&o, &c, &i);
-	}
-	catch (love::Exception &e)
-	{
-		luaL_error(L, "%s", e.what());
-	}
+	)
 	lua_pushnumber(L, Physics::scaleUp(o.distance));
 	lua_pushnumber(L, Physics::scaleUp(o.pointA.x));
 	lua_pushnumber(L, Physics::scaleUp(o.pointA.y));

src/modules/physics/box2d/wrap_Body.cpp

 int w_Body_destroy(lua_State *L)
 {
 	Body *t = luax_checkbody(L, 1);
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		t->destroy();
-	}
-	catch(love::Exception &e)
-	{
-		luaL_error(L, "%s", e.what());
-	}
+	)
 	return 0;
 }
 

src/modules/physics/box2d/wrap_Fixture.cpp

 int w_Fixture_destroy(lua_State *L)
 {
 	Fixture *t = luax_checkfixture(L, 1);
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		t->destroy();
-	}
-	catch(love::Exception &e)
-	{
-		luaL_error(L, "%s", e.what());
-	}
+	)
 	return 0;
 }
 

src/modules/physics/box2d/wrap_Joint.cpp

 int w_Joint_destroy(lua_State *L)
 {
 	Joint *t = luax_checkjoint(L, 1);
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		t->destroyJoint();
-	}
-	catch(love::Exception &e)
-	{
-		luaL_error(L, "%s", e.what());
-	}
+	)
 	return 0;
 }
 

src/modules/physics/box2d/wrap_Physics.cpp

 int w_setMeter(lua_State *L)
 {
 	int arg1 = luaL_checkint(L, 1);
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		Physics::setMeter(arg1);
-	}
-	catch(love::Exception &e)
-	{
-		return luaL_error(L, e.what());
-	}
+	)
 	return 0;
 
 }
 {
 	if (instance == 0)
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			instance = new Physics();
-		}
-		catch(Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 		instance->retain();

src/modules/physics/box2d/wrap_World.cpp

 int w_World_destroy(lua_State *L)
 {
 	World *t = luax_checkworld(L, 1);
-	try
-	{
+	LOVE_EH_CATCH_AND_ERROR
+	(
 		t->destroy();
-	}
-	catch(love::Exception &e)
-	{
-		luaL_error(L, "%s", e.what());
-	}
+	)
 	return 0;
 }
 

src/modules/sound/wrap_Sound.cpp

 		int bits = luaL_optint(L, 3, Decoder::DEFAULT_BITS);
 		int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
 
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			t = instance->newSoundData(samples, sampleRate, bits, channels);
-		}
-		catch(love::Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
-
+		)
 	}
 	// Must be string or decoder.
 	else
 			lua_replace(L, 1);
 		}
 
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			t = instance->newSoundData(luax_checkdecoder(L, 1));
-		}
-		catch(love::Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 
 	luax_newtype(L, "SoundData", SOUND_SOUND_DATA_T, (void *)t);
 			return luaL_error(L, "Extension \"%s\" not supported.", data->getExtension().c_str());
 		luax_newtype(L, "Decoder", SOUND_DECODER_T, (void *)t);
 	}
-	catch(love::Exception &e)
+	catch (love::Exception &e)
 	{
 		data->release();
 		return luaL_error(L, e.what());
 {
 	if (instance == 0)
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			instance = new lullaby::Sound();
-		}
-		catch(Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 		instance->retain();

src/modules/thread/wrap_Thread.cpp

 		luax_convobj(L, 2, "filesystem", "newFile");
 	if (luax_istype(L, 2, FILESYSTEM_FILE_T))
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			data = luax_checktype<love::filesystem::File>(L, 2, "File", FILESYSTEM_FILE_T)->read();
-		}
-		catch(love::Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 	{
 {
 	if (instance == 0)
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			instance = new ThreadModule();
 			lua_getglobal(L, "love");
 			Thread *curthread = instance->getThread("main");
 			curthread->unlock();
 			luax_newtype(L, "Thread", THREAD_THREAD_T, (void *)curthread);
 			lua_setfield(L, -2, "_curthread");
-		}
-		catch(Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 		instance->retain();

src/modules/timer/wrap_Timer.cpp

 {
 	if (instance == 0)
 	{
-		try
-		{
+		LOVE_EH_CATCH_AND_ERROR
+		(
 			instance = new love::timer::sdl::Timer();
-
-		}
-		catch(Exception &e)
-		{
-			return luaL_error(L, e.what());
-		}
+		)
 	}
 	else
 		instance->retain();