View source code
							
							
						
								Display the source code in std/exception.d from which this
								page was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create a
								Bugzilla issue.
							
						
							
								Improve this page
							
							
					
								Quickly fork, edit online, and submit a pull request for this page.
								Requires a signed-in GitHub account. This works well for small changes.
								If you'd like to make larger changes you may want to consider using
								local clone.
							
						Module std.exception
This module defines functions related to exceptions and general error handling. It also defines functions intended to aid in unit testing.
| Category | Functions | 
|---|---|
| Assumptions | assertNotThrownassertThrownassumeUniqueassumeWontThrowmayPointTo | 
| Enforce | doesPointToenforceerrnoEnforce | 
| Handlers | collectExceptioncollectExceptionMsgifThrownhandle | 
| Other | basicExceptionCtorsemptyExceptionMsgErrnoExceptionRangePrimitive | 
Example
Synopis
import coreFunctions
| Name | Description | 
|---|---|
| 
									assertNotThrown(expression, msg, file, line)
								 | Asserts that the given expression does not throw the given type
    of Throwable. If aThrowableof the given type is thrown,
    it is caught and does not escape assertNotThrown. Rather, anAssertErroris thrown. However, any otherThrowables will escape. | 
| 
									assertThrown(expression, msg, file, line)
								 | Asserts that the given expression throws the given type of Throwable.
    TheThrowableis caught and does not escape assertThrown. However,
    any otherThrowables will escape, and if noThrowableof the given type is thrown, then anAssertErroris thrown. | 
| 
									assumeUnique(array)
								 | Casts a mutable array to an immutable array in an idiomatic
 manner. Technically, assumeUniquejust inserts a cast,
 but its name documents assumptions on the part of the
 caller.assumeUnique(arr)should only be called when
 there are no more active mutable aliases to elements of arr. To strengthen this assumption,assumeUnique(arr)also clearsarrbefore returning. Essentially assumeUnique(arr)indicates commitment from the caller that there
 is no more mutable access to any ofarr's elements
 (transitively), and that all future accesses will be done through
 the immutable array returned byassumeUnique. | 
| 
									assumeWontThrow(expr, msg, file, line)
								 | Wraps a possibly-throwing expression in a nothrowwrapper so that it
 can be called by anothrowfunction. | 
| 
									collectException(expression, result)
								 | Catches and returns the exception thrown from the given expression.
    If no exception is thrown, then null is returned and resultis
    set to the result of the expression. | 
| 
									collectException(expression)
								 | Catches and returns the exception thrown from the given expression.
    If no exception is thrown, then null is returned. Ecan bevoid. | 
| 
									collectExceptionMsg(expression)
								 | Catches the exception thrown from the given expression and returns the
    msg property of that exception. If no exception is thrown, then null is
    returned. Ecan bevoid. | 
| 
									doesPointTo(source, target)
								 | Checks whether a given source object contains pointers or references to a given target object. | 
| 
									enforce(value, dg)
								 | Enforces that the given value is true. If the given value is false, an exception is thrown. The | 
| 
									handle(input)
								 | Handle exceptions thrown from range primitives. | 
| 
									ifThrown(expression, errorHandler)
								 | ML-style functional exception handling. Runs the supplied expression and
    returns its result. If the expression throws a Throwable, runs the
    supplied error handler instead and return its result. The error handler's
    type must be the same as the expression's type. | 
| 
									mayPointTo(source, target)
								 | Checks whether a given source object contains pointers or references to a given target object. | 
Classes
| Name | Description | 
|---|---|
| 
									ErrnoException
								 | Thrown if errors that set errnooccur. | 
Enums
| Name | Description | 
|---|---|
| 
									RangePrimitive
								 | This enumis used to select the primitives of the range to handle by thehandlerange wrapper. The values of theenumcan beOR'd to
  select multiple primitives to be handled. | 
Templates
| Name | Description | 
|---|---|
| 
									basicExceptionCtors
								 | Convenience mixin for trivially sub-classing exceptions | 
| 
									enforce
								 | Enforces that the given value is true. If the given value is false, an exception is thrown. The | 
Manifest constants
| Name | Type | Description | 
|---|---|---|
| emptyExceptionMsg | Value that collectExceptionMsg returns when it catches an exception with an empty exception message. | 
Aliases
| Name | Type | Description | 
|---|---|---|
| errnoEnforce | enforce!ErrnoException | Enforces that the given value is true, throwing an ErrnoExceptionif it
    is not. | 
Authors
License
					Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.