<commit_before>---
title: Error Handling
question: Why can GraphQL predetermine if a query is valid?
answers: ["GraphQL language has a strong type system", "GraphQL is a new language", "GraphQL can be implemented in various languages", "GraphQL has security built-in"]
correctAnswer: 0
description: Handling Errors on GraphQL
---

All applications fail, and GraphQL it's no different. Some clients may ask for information that's not available or execute a forbidden action. In this chapter, you'll understand how GraphQL and Graphene address these issues.

### Schema Errors
Being a language with a strong type system, GraphQL can predetermine if a query is valid. All the fields from queries and mutations have a strong type, so requesting and inputting wrong data will generate an error.

Try it out! On the links query, ask for the `cheese` field and see how GraphQL returns back an error:

![](http://i.imgur.com/9F0jCC7.png)

### Graphene Errors
On the application level, you can use the `GraphQLError` class or the good and old [Python exceptions](https://docs.python.org/3/tutorial/errors.html).

You already used the `raise Exception('message')` through the code, for example, when checking if the user or link were valid before creating a vote. Let's try the other one!<commit_msg>Fix typo in error handling<commit_after>---
title: Error Handling
question: Why can GraphQL predetermine if a query is valid?
answers: ["GraphQL language has a strong type system", "GraphQL is a new language", "GraphQL can be implemented in various languages", "GraphQL has security built-in"]
correctAnswer: 0
description: Handling Errors on GraphQL
---

All applications fail, and GraphQL is no different. Some clients may ask for information that's not available or execute a forbidden action. In this chapter, you'll understand how GraphQL and Graphene address these issues.

### Schema Errors
Being a language with a strong type system, GraphQL can predetermine if a query is valid. All the fields from queries and mutations have a strong type, so requesting and inputting wrong data will generate an error.

Try it out! On the links query, ask for the `cheese` field and see how GraphQL returns back an error:

![](http://i.imgur.com/9F0jCC7.png)

### Graphene Errors
On the application level, you can use the `GraphQLError` class or the good and old [Python exceptions](https://docs.python.org/3/tutorial/errors.html).

You already used the `raise Exception('message')` through the code, for example, when checking if the user or link were valid before creating a vote. Let's try the other one!
{'fraction_non_alphanumeric': 0.07062910073330761, 'fraction_numerical': 0.0038595137012736396, 'mean_word_length': 4.747228381374723, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4036983', 'n_tokens_mistral': 700, 'n_tokens_neox': 664, 'n_words': 377}