@@ -704,6 +704,11 @@ def flush_stdio
704
704
STDERR . flush unless STDERR . closed?
705
705
end
706
706
707
+ def exit_with_exception ( e )
708
+ @exit_code = 1
709
+ Rubinius ::Logger . log_exception "An exception occurred #{ @stage } " , e
710
+ end
711
+
707
712
# Cleanup and at_exit processing.
708
713
def epilogue
709
714
@stage = "running at_exit handlers"
@@ -723,8 +728,7 @@ def epilogue
723
728
flush_stdio
724
729
725
730
rescue Object => e
726
- Rubinius ::Logger . log_exception "An exception occurred #{ @stage } " , e
727
- @exit_code = 1
731
+ exit_with_exception e
728
732
end
729
733
730
734
# Exit.
@@ -776,6 +780,34 @@ def done
776
780
Process . exit! @exit_code
777
781
end
778
782
783
+ def handle_exception ( e )
784
+ case e
785
+ when SystemExit
786
+ @exit_code = e . status
787
+ when SyntaxError
788
+ @exit_code = 1
789
+
790
+ show_syntax_error ( e )
791
+
792
+ STDERR . puts "\n Backtrace:"
793
+ STDERR . puts
794
+ STDERR . puts e . awesome_backtrace . show
795
+ when Interrupt
796
+ exit_with_exception e
797
+ when SignalException
798
+ Signal . trap ( e . signo , "SIG_DFL" )
799
+ Process . kill e . signo , Process . pid
800
+ when nil
801
+ # what?
802
+ else
803
+ exit_with_exception e
804
+ end
805
+ rescue Object => e
806
+ exit_with_exception e
807
+ ensure
808
+ epilogue
809
+ end
810
+
779
811
# Orchestrate everything.
780
812
def main
781
813
preamble
@@ -795,33 +827,8 @@ def main
795
827
script
796
828
repl
797
829
798
- rescue SystemExit => e
799
- @exit_code = e . status
800
-
801
- epilogue
802
- rescue SyntaxError => e
803
- @exit_code = 1
804
-
805
- show_syntax_error ( e )
806
-
807
- STDERR . puts "\n Backtrace:"
808
- STDERR . puts
809
- STDERR . puts e . awesome_backtrace . show
810
- epilogue
811
- rescue Interrupt => e
812
- @exit_code = 1
813
-
814
- Rubinius ::Logger . log_exception "An exception occurred #{ @stage } :" , e
815
- epilogue
816
- rescue SignalException => e
817
- Signal . trap ( e . signo , "SIG_DFL" )
818
- Process . kill e . signo , Process . pid
819
- epilogue
820
830
rescue Object => e
821
- @exit_code = 1
822
-
823
- Rubinius ::Logger . log_exception "An exception occurred #{ @stage } :" , e
824
- epilogue
831
+ handle_exception e
825
832
else
826
833
# We do this, run epilogue both in the rescue blocks and also here,
827
834
# so that at_exit{} hooks can read $!.
0 commit comments