I am entering the world of Python and I have a question that has arisen, I have been looking around but I have not found anything that convinces me and I hope that here the hard one will be clarified.
The question is on the topic of exceptions in Python and how to throw and catch them afterwards.
I put an example in Java and I want to know how it could be done in Python:
public void setEdad(int edad) {
if (edad <= 0)
throw new Exception("La edad debe ser positiva.");
this.edad = edad;
}
And then before assigning a value I capture it:
try {
Persona persona = new Persona();
persona.setEdad(-10);
} catch (Exception e) {
System.out.println(e.getMessage());
}
This is a test example to show what I want to achieve.
How could I do that in Python and be able to throw exceptions like in java?
Greetings and thank you.