Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Raising | Error Handling
Mastering Python: Annotations, Errors and Environment
course content

Conteúdo do Curso

Mastering Python: Annotations, Errors and Environment

Mastering Python: Annotations, Errors and Environment

1. Annotations
2. Function Arguments in Details
3. Error Handling
4. Virtual Environment

Raising

Let's learn how to raise an error.

Errors can be raised using the raise keyword:

The TypeError in the example above was raised without a message.

To output an error message, you can pass a string inside the parentheses () after the error object:

Tarefa

You have implemented the perimeter() function that returns the triangle perimeter. This function receives the sides of a triangle (a, b, and c). You need to add error raising to this function.

  1. All received sides should be int or float data type. In another case, the function should raise the TypeError with the message "All sides should be int or float type".
  2. In a triangle, all sides should have a length greater than 0. In other cases, the function should raise the ValueError with the message "All sides should be greater than 0".
  3. In a triangle, the sum of two sides must always be greater than the third side (otherwise, the two sides would not reach each other through the third side). Therefore, if one of the received sides is greater than the sum of the other two, the program must raise the ValueError with the message "It's not a triangle".

Tarefa

You have implemented the perimeter() function that returns the triangle perimeter. This function receives the sides of a triangle (a, b, and c). You need to add error raising to this function.

  1. All received sides should be int or float data type. In another case, the function should raise the TypeError with the message "All sides should be int or float type".
  2. In a triangle, all sides should have a length greater than 0. In other cases, the function should raise the ValueError with the message "All sides should be greater than 0".
  3. In a triangle, the sum of two sides must always be greater than the third side (otherwise, the two sides would not reach each other through the third side). Therefore, if one of the received sides is greater than the sum of the other two, the program must raise the ValueError with the message "It's not a triangle".

Tudo estava claro?

Seção 3. Capítulo 3
toggle bottom row

Raising

Let's learn how to raise an error.

Errors can be raised using the raise keyword:

The TypeError in the example above was raised without a message.

To output an error message, you can pass a string inside the parentheses () after the error object:

Tarefa

You have implemented the perimeter() function that returns the triangle perimeter. This function receives the sides of a triangle (a, b, and c). You need to add error raising to this function.

  1. All received sides should be int or float data type. In another case, the function should raise the TypeError with the message "All sides should be int or float type".
  2. In a triangle, all sides should have a length greater than 0. In other cases, the function should raise the ValueError with the message "All sides should be greater than 0".
  3. In a triangle, the sum of two sides must always be greater than the third side (otherwise, the two sides would not reach each other through the third side). Therefore, if one of the received sides is greater than the sum of the other two, the program must raise the ValueError with the message "It's not a triangle".

Tarefa

You have implemented the perimeter() function that returns the triangle perimeter. This function receives the sides of a triangle (a, b, and c). You need to add error raising to this function.

  1. All received sides should be int or float data type. In another case, the function should raise the TypeError with the message "All sides should be int or float type".
  2. In a triangle, all sides should have a length greater than 0. In other cases, the function should raise the ValueError with the message "All sides should be greater than 0".
  3. In a triangle, the sum of two sides must always be greater than the third side (otherwise, the two sides would not reach each other through the third side). Therefore, if one of the received sides is greater than the sum of the other two, the program must raise the ValueError with the message "It's not a triangle".

Tudo estava claro?

Seção 3. Capítulo 3
toggle bottom row

Raising

Let's learn how to raise an error.

Errors can be raised using the raise keyword:

The TypeError in the example above was raised without a message.

To output an error message, you can pass a string inside the parentheses () after the error object:

Tarefa

You have implemented the perimeter() function that returns the triangle perimeter. This function receives the sides of a triangle (a, b, and c). You need to add error raising to this function.

  1. All received sides should be int or float data type. In another case, the function should raise the TypeError with the message "All sides should be int or float type".
  2. In a triangle, all sides should have a length greater than 0. In other cases, the function should raise the ValueError with the message "All sides should be greater than 0".
  3. In a triangle, the sum of two sides must always be greater than the third side (otherwise, the two sides would not reach each other through the third side). Therefore, if one of the received sides is greater than the sum of the other two, the program must raise the ValueError with the message "It's not a triangle".

Tarefa

You have implemented the perimeter() function that returns the triangle perimeter. This function receives the sides of a triangle (a, b, and c). You need to add error raising to this function.

  1. All received sides should be int or float data type. In another case, the function should raise the TypeError with the message "All sides should be int or float type".
  2. In a triangle, all sides should have a length greater than 0. In other cases, the function should raise the ValueError with the message "All sides should be greater than 0".
  3. In a triangle, the sum of two sides must always be greater than the third side (otherwise, the two sides would not reach each other through the third side). Therefore, if one of the received sides is greater than the sum of the other two, the program must raise the ValueError with the message "It's not a triangle".

Tudo estava claro?

Let's learn how to raise an error.

Errors can be raised using the raise keyword:

The TypeError in the example above was raised without a message.

To output an error message, you can pass a string inside the parentheses () after the error object:

Tarefa

You have implemented the perimeter() function that returns the triangle perimeter. This function receives the sides of a triangle (a, b, and c). You need to add error raising to this function.

  1. All received sides should be int or float data type. In another case, the function should raise the TypeError with the message "All sides should be int or float type".
  2. In a triangle, all sides should have a length greater than 0. In other cases, the function should raise the ValueError with the message "All sides should be greater than 0".
  3. In a triangle, the sum of two sides must always be greater than the third side (otherwise, the two sides would not reach each other through the third side). Therefore, if one of the received sides is greater than the sum of the other two, the program must raise the ValueError with the message "It's not a triangle".

Seção 3. Capítulo 3
Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt