|
9 | 9 | */
|
10 | 10 | module core.exception;
|
11 | 11 |
|
| 12 | +// Compiler lowers final switch default case to this (which is a runtime error) |
| 13 | +void __switch_errorT()(string file = __FILE__, size_t line = __LINE__) @trusted |
| 14 | +{ |
| 15 | + // Consider making this a compile time check. |
| 16 | + version (D_Exceptions) |
| 17 | + throw staticError!SwitchError(file, line, null); |
| 18 | + else |
| 19 | + assert(0, "No appropriate switch clause found"); |
| 20 | +} |
| 21 | + |
| 22 | +version (D_BetterC) |
| 23 | +{ |
| 24 | + // When compiling with -betterC we use template functions so if they are |
| 25 | + // used the bodies are copied into the user's program so there is no need |
| 26 | + // for the D runtime during linking. |
| 27 | + |
| 28 | + // In the future we might want to convert all functions in this module to |
| 29 | + // templates even for ordinary builds instead of providing them as an |
| 30 | + // extern(C) library. |
| 31 | + |
| 32 | + void onOutOfMemoryError()(void* pretend_sideffect = null) @nogc nothrow pure @trusted |
| 33 | + { |
| 34 | + assert(0, "Memory allocation failed"); |
| 35 | + } |
| 36 | + alias onOutOfMemoryErrorNoGC = onOutOfMemoryError; |
| 37 | + |
| 38 | + void onInvalidMemoryOperationError()(void* pretend_sideffect = null) @nogc nothrow pure @trusted |
| 39 | + { |
| 40 | + assert(0, "Invalid memory operation"); |
| 41 | + } |
| 42 | +} |
| 43 | +else: |
| 44 | + |
12 | 45 | /**
|
13 | 46 | * Thrown on a range error.
|
14 | 47 | */
|
@@ -580,16 +613,6 @@ extern (C) void onSwitchError( string file = __FILE__, size_t line = __LINE__ )
|
580 | 613 | assert(0, "No appropriate switch clause found");
|
581 | 614 | }
|
582 | 615 |
|
583 |
| -// Compiler lowers final switch default case to this (which is a runtime error) |
584 |
| -void __switch_errorT()(string file = __FILE__, size_t line = __LINE__) @trusted |
585 |
| -{ |
586 |
| - // Consider making this a compile time check. |
587 |
| - version (D_Exceptions) |
588 |
| - throw staticError!SwitchError(file, line, null); |
589 |
| - else |
590 |
| - assert(0, "No appropriate switch clause found"); |
591 |
| -} |
592 |
| - |
593 | 616 | /**
|
594 | 617 | * A callback for unicode errors in D. A $(LREF UnicodeException) will be thrown.
|
595 | 618 | *
|
|
0 commit comments