# for http://blender.stackexchange.com/questions/56087/check-if-an-operation-can-be-applied-without-runtime-errors
import bpy
if bpy.ops.mesh.fill_grid.poll():
print("correct context")
try:
bpy.ops.mesh.fill_grid()
except RuntimeError as exception:
error = "\n".join(exception.args)
print("error:", error)
else:
print ("incorrect context")