Better error handling in Graph constructor