Changeset 42

Show
Ignore:
Timestamp:
10/31/08 19:13:27 (4 years ago)
Author:
sean
Message:

* Reclassified most runtime-generated errors as Errors rather than Exceptions. This involved both a parent reasignment and a name change. At this point, the only remaining Exception is UnicodeException?.
* Renamed ArrayBoundsException? to RangeError? in an attempt to be more general.
* Renamed onArrayBoundsError callback to onRangeError to make handling of these conditions more general as well. Ideally, this will allow the same callback to be used for other purposes in the future.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/D1.0/src/common/core/exception.d

    r29 r42  
    1919 
    2020/** 
    21  * Thrown on an array bounds error. 
    22  */ 
    23 class ArrayBoundsException : Exception 
    24 { 
    25     this( string file, size_t line ) 
    26     { 
    27         super( "Array index out of bounds", file, line ); 
     21 * Thrown on a range error. 
     22 */ 
     23class RangeError : Error 
     24{ 
     25    this( string file, size_t line ) 
     26    { 
     27        super( "Range violation", file, line ); 
    2828    } 
    2929} 
     
    3333 * Thrown on an assert error. 
    3434 */ 
    35 class AssertException : Exception 
     35class AssertError : Error 
    3636{ 
    3737    this( string file, size_t line ) 
     
    5050 * Thrown on finalize error. 
    5151 */ 
    52 class FinalizeException : Exception 
     52class FinalizeError : Error 
    5353{ 
    5454    ClassInfo   info; 
     
    7070 * Thrown on an out of memory error. 
    7171 */ 
    72 class OutOfMemoryException : Exception 
     72class OutOfMemoryError : Error 
    7373{ 
    7474    this( string file, size_t line ) 
     
    8787 * Thrown on a switch error. 
    8888 */ 
    89 class SwitchException : Exception 
     89class SwitchError : Error 
    9090{ 
    9191    this( string file, size_t line ) 
     
    135135/** 
    136136 * A callback for assert errors in D.  The user-supplied assert handler will 
    137  * be called if one has been supplied, otherwise an AssertException will be 
     137 * be called if one has been supplied, otherwise an AssertError will be thrown. 
     138 * 
     139 * Params: 
     140 *  file = The name of the file that signaled this error. 
     141 *  line = The line number on which this error occurred. 
     142 */ 
     143extern (C) void onAssertError( string file, size_t line ) 
     144
     145    if( assertHandler is null ) 
     146        throw new AssertError( file, line ); 
     147    assertHandler( file, line ); 
     148
     149 
     150 
     151/** 
     152 * A callback for assert errors in D.  The user-supplied assert handler will 
     153 * be called if one has been supplied, otherwise an AssertError will be thrown. 
     154 * 
     155 * Params: 
     156 *  file = The name of the file that signaled this error. 
     157 *  line = The line number on which this error occurred. 
     158 *  msg  = An error message supplied by the user. 
     159 */ 
     160extern (C) void onAssertErrorMsg( string file, size_t line, string msg ) 
     161
     162    if( assertHandler is null ) 
     163        throw new AssertError( msg, file, line ); 
     164    assertHandler( file, line, msg ); 
     165
     166 
     167 
     168/////////////////////////////////////////////////////////////////////////////// 
     169// Internal Error Callbacks 
     170/////////////////////////////////////////////////////////////////////////////// 
     171 
     172 
     173/** 
     174 * A callback for range errors in D.  A RangeError will be thrown. 
     175 * 
     176 * Params: 
     177 *  file = The name of the file that signaled this error. 
     178 *  line = The line number on which this error occurred. 
     179 * 
     180 * Throws: 
     181 *  RangeError. 
     182 */ 
     183extern (C) void onRangeError( string file, size_t line ) 
     184
     185    throw new RangeError( file, line ); 
     186
     187 
     188 
     189/** 
     190 * A callback for finalize errors in D.  A FinalizeError will be thrown. 
     191 * 
     192 * Params: 
     193 *  e = The exception thrown during finalization. 
     194 * 
     195 * Throws: 
     196 *  FinalizeError. 
     197 */ 
     198extern (C) void onFinalizeError( ClassInfo info, Exception ex ) 
     199
     200    throw new FinalizeError( info, ex ); 
     201
     202 
     203 
     204/** 
     205/** 
     206 * A callback for out of memory errors in D.  An OutOfMemoryError will be 
    138207 * thrown. 
    139208 * 
    140  * Params: 
    141  *  file = The name of the file that signaled this error. 
    142  *  line = The line number on which this error occurred. 
    143  */ 
    144 extern (C) void onAssertError( string file, size_t line ) 
    145 
    146     if( assertHandler is null ) 
    147         throw new AssertException( file, line ); 
    148     assertHandler( file, line ); 
    149 
    150  
    151  
    152 /** 
    153  * A callback for assert errors in D.  The user-supplied assert handler will 
    154  * be called if one has been supplied, otherwise an AssertException will be 
    155  * thrown. 
    156  * 
    157  * Params: 
    158  *  file = The name of the file that signaled this error. 
    159  *  line = The line number on which this error occurred. 
    160  *  msg  = An error message supplied by the user. 
    161  */ 
    162 extern (C) void onAssertErrorMsg( string file, size_t line, string msg ) 
    163 
    164     if( assertHandler is null ) 
    165         throw new AssertException( msg, file, line ); 
    166     assertHandler( file, line, msg ); 
    167 
    168  
    169  
    170 /////////////////////////////////////////////////////////////////////////////// 
    171 // Internal Error Callbacks 
    172 /////////////////////////////////////////////////////////////////////////////// 
    173  
    174  
    175 /** 
    176  * A callback for array bounds errors in D.  An ArrayBoundsException will be 
    177  * thrown. 
    178  * 
    179  * Params: 
    180  *  file = The name of the file that signaled this error. 
    181  *  line = The line number on which this error occurred. 
    182  * 
    183  * Throws: 
    184  *  ArrayBoundsException. 
    185  */ 
    186 extern (C) void onArrayBoundsError( string file, size_t line ) 
    187 
    188     throw new ArrayBoundsException( file, line ); 
    189 
    190  
    191  
    192 /** 
    193  * A callback for finalize errors in D.  A FinalizeException will be thrown. 
    194  * 
    195  * Params: 
    196  *  e = The exception thrown during finalization. 
    197  * 
    198  * Throws: 
    199  *  FinalizeException. 
    200  */ 
    201 extern (C) void onFinalizeError( ClassInfo info, Exception ex ) 
    202 
    203     throw new FinalizeException( info, ex ); 
    204 
    205  
    206  
    207 /** 
    208  * A callback for out of memory errors in D.  An OutOfMemoryException will be 
    209  * thrown. 
    210  * 
    211  * Throws: 
    212  *  OutOfMemoryException. 
     209 * Throws: 
     210 *  OutOfMemoryError. 
    213211 */ 
    214212extern (C) void onOutOfMemoryError() 
     
    216214    // NOTE: Since an out of memory condition exists, no allocation must occur 
    217215    //       while generating this object. 
    218     throw cast(OutOfMemoryException) cast(void*) OutOfMemoryException.classinfo.init; 
    219 } 
    220  
    221  
    222 /** 
    223  * A callback for switch errors in D.  A SwitchException will be thrown. 
    224  * 
    225  * Params: 
    226  *  file = The name of the file that signaled this error. 
    227  *  line = The line number on which this error occurred. 
    228  * 
    229  * Throws: 
    230  *  SwitchException
     216    throw cast(OutOfMemoryError) cast(void*) OutOfMemoryError.classinfo.init; 
     217} 
     218 
     219 
     220/** 
     221 * A callback for switch errors in D.  A SwitchError will be thrown. 
     222 * 
     223 * Params: 
     224 *  file = The name of the file that signaled this error. 
     225 *  line = The line number on which this error occurred. 
     226 * 
     227 * Throws: 
     228 *  SwitchError
    231229 */ 
    232230extern (C) void onSwitchError( string file, size_t line ) 
    233231{ 
    234     throw new SwitchException( file, line ); 
     232    throw new SwitchError( file, line ); 
    235233} 
    236234 
  • branches/D1.0/src/compiler/dmd/dmain2.d

    r38 r42  
    100100extern (C) void onAssertError(string file, size_t line); 
    101101extern (C) void onAssertErrorMsg(string file, size_t line, string msg); 
    102 extern (C) void onArrayBoundsError(string file, size_t line); 
     102extern (C) void onRangeError(string file, size_t line); 
    103103extern (C) void onHiddenFuncError(Object o); 
    104104extern (C) void onSwitchError(string file, size_t line); 
     
    123123extern (C) void _d_array_bounds(string file, uint line) 
    124124{ 
    125     onArrayBoundsError(file, line); 
     125    onRangeError(file, line); 
    126126} 
    127127 
  • trunk/src/common/core/exception.d

    r29 r42  
    1212private 
    1313{ 
    14     alias void function( string file, size_t line, string msg = null ) assertHandlerType; 
    15  
    16     assertHandlerType   assertHandler   = null; 
    17 } 
    18  
    19  
    20 /** 
    21  * Thrown on an array bounds error. 
    22  */ 
    23 class ArrayBoundsException : Exception 
    24 { 
    25     this( string file, size_t line ) 
    26     { 
    27         super( "Array index out of bounds", file, line ); 
     14    alias void function( string file, size_t line, string msg = null ) assertHandlerType; 
     15 
     16    assertHandlerType assertHandler   = null; 
     17} 
     18 
     19 
     20/** 
     21 * Thrown on a range error. 
     22 */ 
     23class RangeError : Error 
     24{ 
     25    this( string file, size_t line ) 
     26    { 
     27        super( "Range violation", file, line ); 
    2828    } 
    2929} 
     
    3333 * Thrown on an assert error. 
    3434 */ 
    35 class AssertException : Exception 
     35class AssertError : Error 
    3636{ 
    3737    this( string file, size_t line ) 
     
    5050 * Thrown on finalize error. 
    5151 */ 
    52 class FinalizeException : Exception 
     52class FinalizeError : Error 
    5353{ 
    5454    ClassInfo   info; 
     
    7070 * Thrown on hidden function error. 
    7171 */ 
    72 class HiddenFuncException : Exception 
     72class HiddenFuncError : Error 
    7373{ 
    7474    this( ClassInfo ci ) 
     
    8282 * Thrown on an out of memory error. 
    8383 */ 
    84 class OutOfMemoryException : Exception 
     84class OutOfMemoryError : Error 
    8585{ 
    8686    this( string file, size_t line ) 
     
    9999 * Thrown on a switch error. 
    100100 */ 
    101 class SwitchException : Exception 
     101class SwitchError : Error 
    102102{ 
    103103    this( string file, size_t line ) 
     
    147147/** 
    148148 * A callback for assert errors in D.  The user-supplied assert handler will 
    149  * be called if one has been supplied, otherwise an AssertException will be 
     149 * be called if one has been supplied, otherwise an AssertError will be thrown. 
     150 * 
     151 * Params: 
     152 *  file = The name of the file that signaled this error. 
     153 *  line = The line number on which this error occurred. 
     154 */ 
     155extern (C) void onAssertError( string file, size_t line ) 
     156
     157    if( assertHandler is null ) 
     158        throw new AssertError( file, line ); 
     159    assertHandler( file, line ); 
     160
     161 
     162 
     163/** 
     164 * A callback for assert errors in D.  The user-supplied assert handler will 
     165 * be called if one has been supplied, otherwise an AssertError will be thrown. 
     166 * 
     167 * Params: 
     168 *  file = The name of the file that signaled this error. 
     169 *  line = The line number on which this error occurred. 
     170 *  msg  = An error message supplied by the user. 
     171 */ 
     172extern (C) void onAssertErrorMsg( string file, size_t line, string msg ) 
     173
     174    if( assertHandler is null ) 
     175        throw new AssertError( msg, file, line ); 
     176    assertHandler( file, line, msg ); 
     177
     178 
     179 
     180/////////////////////////////////////////////////////////////////////////////// 
     181// Internal Error Callbacks 
     182/////////////////////////////////////////////////////////////////////////////// 
     183 
     184 
     185/** 
     186 * A callback for array bounds errors in D.  A RangeError will be thrown. 
     187 * 
     188 * Params: 
     189 *  file = The name of the file that signaled this error. 
     190 *  line = The line number on which this error occurred. 
     191 * 
     192 * Throws: 
     193 *  RangeError. 
     194 */ 
     195extern (C) void onRangeError( string file, size_t line ) 
     196
     197    throw new RangeError( file, line ); 
     198
     199 
     200 
     201/** 
     202 * A callback for finalize errors in D.  A FinalizeError will be thrown. 
     203 * 
     204 * Params: 
     205 *  e = The exception thrown during finalization. 
     206 * 
     207 * Throws: 
     208 *  FinalizeError. 
     209 */ 
     210extern (C) void onFinalizeError( ClassInfo info, Exception ex ) 
     211
     212    throw new FinalizeError( info, ex ); 
     213
     214 
     215 
     216/** 
     217 * A callback for hidden function errors in D.  A HiddenFuncError will be 
    150218 * thrown. 
    151219 * 
    152  * Params: 
    153  *  file = The name of the file that signaled this error. 
    154  *  line = The line number on which this error occurred. 
    155  */ 
    156 extern (C) void onAssertError( string file, size_t line ) 
    157 
    158     if( assertHandler is null ) 
    159         throw new AssertException( file, line ); 
    160     assertHandler( file, line ); 
    161 
    162  
    163  
    164 /** 
    165  * A callback for assert errors in D.  The user-supplied assert handler will 
    166  * be called if one has been supplied, otherwise an AssertException will be 
     220 * Throws: 
     221 *  HiddenFuncError. 
     222 */ 
     223extern (C) void onHiddenFuncError( Object o ) 
     224
     225    throw new HiddenFuncError( o.classinfo ); 
     226
     227 
     228 
     229/** 
     230 * A callback for out of memory errors in D.  An OutOfMemoryError will be 
    167231 * thrown. 
    168232 * 
    169  * Params: 
    170  *  file = The name of the file that signaled this error. 
    171  *  line = The line number on which this error occurred. 
    172  *  msg  = An error message supplied by the user. 
    173  */ 
    174 extern (C) void onAssertErrorMsg( string file, size_t line, string msg ) 
    175 
    176     if( assertHandler is null ) 
    177         throw new AssertException( msg, file, line ); 
    178     assertHandler( file, line, msg ); 
    179 
    180  
    181  
    182 /////////////////////////////////////////////////////////////////////////////// 
    183 // Internal Error Callbacks 
    184 /////////////////////////////////////////////////////////////////////////////// 
    185  
    186  
    187 /** 
    188  * A callback for array bounds errors in D.  An ArrayBoundsException will be 
    189  * thrown. 
    190  * 
    191  * Params: 
    192  *  file = The name of the file that signaled this error. 
    193  *  line = The line number on which this error occurred. 
    194  * 
    195  * Throws: 
    196  *  ArrayBoundsException. 
    197  */ 
    198 extern (C) void onArrayBoundsError( string file, size_t line ) 
    199 
    200     throw new ArrayBoundsException( file, line ); 
    201 
    202  
    203  
    204 /** 
    205  * A callback for finalize errors in D.  A FinalizeException will be thrown. 
    206  * 
    207  * Params: 
    208  *  e = The exception thrown during finalization. 
    209  * 
    210  * Throws: 
    211  *  FinalizeException. 
    212  */ 
    213 extern (C) void onFinalizeError( ClassInfo info, Exception ex ) 
    214 
    215     throw new FinalizeException( info, ex ); 
    216 
    217  
    218  
    219 /** 
    220  * A callback for hidden function errors in D.  A HiddenFuncException will be 
    221  * thrown. 
    222  * 
    223  * Throws: 
    224  *  HiddenFuncException. 
    225  */ 
    226 extern (C) void onHiddenFuncError( Object o ) 
    227 
    228     throw new HiddenFuncException( o.classinfo ); 
    229 
    230  
    231  
    232 /** 
    233  * A callback for out of memory errors in D.  An OutOfMemoryException will be 
    234  * thrown. 
    235  * 
    236  * Throws: 
    237  *  OutOfMemoryException. 
     233 * Throws: 
     234 *  OutOfMemoryError. 
    238235 */ 
    239236extern (C) void onOutOfMemoryError() 
     
    241238    // NOTE: Since an out of memory condition exists, no allocation must occur 
    242239    //       while generating this object. 
    243     throw cast(OutOfMemoryException) cast(void*) OutOfMemoryException.classinfo.init; 
    244 } 
    245  
    246  
    247 /** 
    248  * A callback for switch errors in D.  A SwitchException will be thrown. 
    249  * 
    250  * Params: 
    251  *  file = The name of the file that signaled this error. 
    252  *  line = The line number on which this error occurred. 
    253  * 
    254  * Throws: 
    255  *  SwitchException
     240    throw cast(OutOfMemoryError) cast(void*) OutOfMemoryError.classinfo.init; 
     241} 
     242 
     243 
     244/** 
     245 * A callback for switch errors in D.  A SwitchError will be thrown. 
     246 * 
     247 * Params: 
     248 *  file = The name of the file that signaled this error. 
     249 *  line = The line number on which this error occurred. 
     250 * 
     251 * Throws: 
     252 *  SwitchError
    256253 */ 
    257254extern (C) void onSwitchError( string file, size_t line ) 
    258255{ 
    259     throw new SwitchException( file, line ); 
     256    throw new SwitchError( file, line ); 
    260257} 
    261258 
  • trunk/src/compiler/dmd/dmain2.d

    r38 r42  
    102102extern (C) void onAssertError(string file, size_t line); 
    103103extern (C) void onAssertErrorMsg(string file, size_t line, string msg); 
    104 extern (C) void onArrayBoundsError(string file, size_t line); 
     104extern (C) void onRangeError(string file, size_t line); 
    105105extern (C) void onHiddenFuncError(Object o); 
    106106extern (C) void onSwitchError(string file, size_t line); 
     
    125125extern (C) void _d_array_bounds(string file, uint line) 
    126126{ 
    127     onArrayBoundsError(file, line); 
     127    onRangeError(file, line); 
    128128} 
    129129