Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jordy33 committed Sep 17, 2014
0 parents commit d9cb387
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Python 3
Test exceptions
10 changes: 10 additions & 0 deletions classexeption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class MiError(Exception):
def __init__(self, valor):
self.valor = valor
def __str__(self):
return repr(self.valor)

try:
raise MiError(2*2)
except MyError as e:
print('Ocurrió mi excepción, valor:', e.encode('utf-8'))
35 changes: 35 additions & 0 deletions classexeption2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# define Python user-defined exceptions
class Error(Exception):
"""Base class for other exceptions"""
pass

class ValueTooSmallError(Error):
"""Raised when the input value is too small"""
pass

class ValueTooLargeError(Error):
"""Raised when the input value is too large"""
pass

# our main program
# user guesses a number until he/she gets it right

# you need to guess this number
number = 10

while True:
try:
i_num = int(input("Enter a number: "))
if i_num < number:
raise ValueTooSmallError
elif i_num > number:
raise ValueTooLargeError
break
except ValueTooSmallError:
print("This value is too small, try again!")
print(" ")
except ValueTooLargeError:
print("This value is too large, try again!")
print(" ")

print("Congratulations! You guessed it correctly.")
11 changes: 11 additions & 0 deletions denominator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
while True:
# Read int from console.
denominator = int(input())

# Use int as denominator.
try:
i = 1 / denominator
except:
print("Error")
else:
print("OK")
10 changes: 10 additions & 0 deletions divzero.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def mistake(name):
raise Exception(name+" caused exception")


try:
x=1/0
except ZeroDivisionError:
print ("Tryed div by zero")
print ("salir")
mistake("error de conexion")
5 changes: 5 additions & 0 deletions openfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try:
f=open("abc")
except:
print("except hit")
raise
1 change: 1 addition & 0 deletions raise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
raise ZeroDivisionError

0 comments on commit d9cb387

Please sign in to comment.