Better reporting of cascading exceptions
[bpt/mlt.git] / src / lib / main.sml
index 139686a..9ffaf5c 100644 (file)
@@ -45,11 +45,15 @@ struct
                                OS.Process.success))
        end handle ex => (Web.setExn ex;
                          Web.clear ();
-                         Templates.exnFn ();
-                         if Web.noOutput () then
-                             (print "Status: 500\nContent-type: text/plain\n\nAn exception!\n\n";
-                              app (fn s => print (s ^ "\n")) (SMLofNJ.exnHistory ex))
-                         else
-                             Web.output ();
+                         (Templates.exnFn ();
+                          if Web.noOutput () then
+                              (print "Status: 500\nContent-type: text/plain\n\nUncaught exception:\n\n";
+                               app (fn s => print (s ^ "\n")) (SMLofNJ.exnHistory ex))
+                          else
+                              Web.output ())
+                         handle ex' => (print "Status: 500\nContent-type : text/plain\n\nUncaught exception:\n\n";
+                                        app (fn s => print ("\t" ^ s ^ "\n")) (SMLofNJ.exnHistory ex);
+                                        print "\nAnother exception raised in exception handler:\n\n";
+                                        app (fn s => print ("\t" ^ s ^ "\n")) (SMLofNJ.exnHistory ex'));
                          OS.Process.failure)
 end
\ No newline at end of file