1 // PERMUTE_ARGS: -O -fPIC
3 extern(C) int printf(const char*, ...);
5 /****************************************************/
35 printf("finally 1\n");
54 /****************************************************/
57 class IntException : Exception
82 for(int WARMUPS = 2; WARMUPS-- > 0; )
84 for(total_x = 0, i = 0; i < cIterations; ++i)
86 total_nox += fn2_nox();
90 for(total_nox = 0, i = 0; i < cIterations; ++i)
92 printf("i = %d\n", i);
97 throw new IntException(z);
101 printf("catch, i = %d\n", i);
102 total_x += x.getValue();
107 printf("iterations %d totals: %ld, %ld\n", cIterations, total_x, total_nox);
116 /****************************************************/
146 /****************************************************/
150 this(void delegate() dg_) { dg = dg_; }
152 void stuff() { dg(); }
157 printf("Starting test\n");
167 throw new Exception("test1");
172 auto es = e.toString();
173 printf("%.*s\n", es.length, es.ptr);
181 printf("initial test.\n");
189 Tester t = new Tester(
195 throw new Exception("test2");
215 string es = e.toString;
216 printf("%.*s\n", es.length, es.ptr);
230 Tester t2 = new Tester(
236 throw new Exception("test3");
241 printf("Never called.\n");
257 string es = e.toString;
258 printf("%.*s\n", es.length, es.ptr);
269 /****************************************************/
279 printf("i: %d\n", i);
287 result ~= cast(char)('a' + i);
290 printf("--- %.*s", result.length, result.ptr);
291 if (result != "tctbta")
295 /****************************************************/
321 /****************************************************/
349 assert(a7 == "abcd");
353 /****************************************************
354 * Exception chaining tests. See also test4.d
355 ****************************************************/
360 throw new Exception("d");
374 throw new Exception("f");
379 assert(e.msg == "d");
380 assert(e.next.msg == "f");
381 assert(!e.next.next);
391 throw new Exception("a");
396 throw new Exception("b");
403 throw new Exception("c");
416 assert(result1513 == 7);
417 assert(e.msg == "a");
418 assert(e.next.msg == "b");
419 assert(e.next.next.msg == "c");
427 throw new Exception("x");
431 throw new Exception("y");
443 throw new Exception("p");
447 throw new Exception("q");
457 assert(e.msg == "p");
458 assert(e.next.msg == "q");
459 assert(e.next.next.msg == "x");
460 assert(e.next.next.next.msg == "y");
461 assert(!e.next.next.next.next);
471 throw new Exception("p2");
475 throw new Exception("q2");
493 throw new Exception("e");
497 throw new Error("t");
501 { // Doesn't catch, because Error is chained to it.
508 assert(z.msg=="t"); // Error comes first
509 assert(z.next is null);
510 assert(z.bypassedException.msg == "e");
515 class AnotherException : Exception
533 throw new Exception("m2");
537 throw new AnotherException("n2");
540 catch(AnotherException s)
541 { // Not caught -- we needed to catch the root cause "m2", not
542 // just the collateral "n2" (which would leave m2 uncaught).
553 assert(f.msg == "m2");
554 assert(f.next.msg == "n2");
555 Throwable e = f.next.next;
556 assert(e.msg == "p2");
557 assert(e.next.msg == "q2");
558 assert(e.next.next.msg == "x");
559 assert(e.next.next.next.msg == "y");
560 assert(!e.next.next.next.next);
564 /****************************************************/
566 void use9568(char [] x, char [] y) {}
578 assert( bug9568() == 7 );
581 /****************************************************/
583 version (DigitalMars)
588 goto L2; // L2 is not addressable.
604 goto L2; // L2 is not addressable.
619 goto L2; // L2 is not addressable.
639 /****************************************************/
650 debug printf("Exception happened\n");
657 assert(foo9(7) == 3);
660 /****************************************************/
669 throw new Exception("BOOM!");
682 catch (Exception e) result = 1;
683 catch (Error e) result = 2;
684 catch (Throwable e) result = 3;
691 catch (Exception e) result = 1;
692 catch (Error e) result = 2;
693 catch (Throwable e) result = 3;
700 catch (Exception e) result = 1;
701 catch (Error e) result = 2;
702 catch (Throwable e) result = 3;
706 /****************************************************/
708 alias Action = void delegate();
716 public Action foo(Action a)
720 B10 elements = new B10;
721 Action[] actions = [a];
723 elements.bar(actions);
725 if (actions.length > 1)
726 elements.bar(actions);
735 public bool bar(ref Action[])
753 assert(a.foo(&d.baz) == &d.baz);
756 /****************************************************/
765 throw new Exception("msg");
782 printf("test10 success\n");
785 /****************************************************/
787 class ParseException : Exception
789 @safe pure nothrow this( string msg )
795 class OverflowException : Exception
797 @safe pure nothrow this( string msg )
808 printf("test11()\n");
809 throw new ParseException("msg");
811 catch( OverflowException e )
813 printf( "catch OverflowException\n" );
815 catch( ParseException e )
817 printf( "catch ParseException: %.*s\n", cast(int) e.msg.length, e.msg.ptr );
823 /****************************************************/
824 // https://issues.dlang.org/show_bug.cgi?id=17481
828 synchronized void trigger(){ new ubyte[1]; }
833 auto k = new shared C17481;
837 /****************************************************/
856 version(DigitalMars) test8();