File tree 1 file changed +57
-0
lines changed
1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -616,3 +616,60 @@ class D(C):
616
616
def act (self ):
617
617
super ().act ()
618
618
print ('eggs' )
619
+
620
+ #-- EXCEPCIONES
621
+ #-- try/except
622
+ try :
623
+ fetcher (x , 4 )
624
+ except IndexError :
625
+ print ('got exception' )
626
+ #-- try/else/except
627
+ try :
628
+ print ('hola' )
629
+ except IndexError :
630
+ pass
631
+ else :
632
+ print ('adios' )
633
+ #-- try/finally
634
+ try :
635
+ fetcher (x , 3 )
636
+ finally :
637
+ print ('after fetch' )
638
+ #-- try/except/finally
639
+ try :
640
+ print ('main' )
641
+ except Exception1 :
642
+ print ('handler1' )
643
+ except Exception2 :
644
+ print ('handler2' )
645
+ else :
646
+ print ('else' )
647
+ finally :
648
+ print ('finally' )
649
+ #-- try/try
650
+ try :
651
+ try :
652
+ print ('main-action' )
653
+ except Exception1 :
654
+ print ('handler1' )
655
+ except Exception2 :
656
+ print ('handler2' )
657
+ else :
658
+ print ('no-error' )
659
+ finally :
660
+ print ('cleanup' )
661
+ #-- raise
662
+ try :
663
+ raise IndexError
664
+ except IndexError :
665
+ print ('got exception' )
666
+
667
+ #-- Assert
668
+ def f (x ):
669
+ assert x < 0 , 'x must be negative'
670
+ return x ** 2
671
+
672
+ #-- with
673
+ with open (r'C:\misc\data' ) as myfile :
674
+ for line in myfile :
675
+ print (line )
You can’t perform that action at this time.
0 commit comments