C# Class Microsoft.Scripting.Runtime.LightExceptions

Provides support for light exceptions. These exceptions are propagated by returning an instance of a private wrapper class containing the exception. Code which is aware of light exceptions will branch to apporiate exception handling blocks when in a try and otherwise return the value up the stack. This avoids using the underlying CLR exception mechanism with overhead such as creating stack traces. When a light exception reaches the boundary of code which is not light exception aware the caller must check to see if a light exception is being thrown and if so raise a .NET exception. This class provides methods for re-writing expression trees to support light exceptions, methods to create light throw objects, check if an object is a light throw object, and turn such an object back into a .NET Exception which can be thrown. Light exceptions also don't build up stack traces or interoperate with filter blocks via 2-pass exception handling.
ファイルを表示 Open project: jschementi/iron

Public Methods

Method Description
CheckAndThrow ( Expression expr ) : Expression

Wraps the expression in a check and rethrow.

CheckAndThrow ( object value ) : object

Throws the exception if the value represents a light exception

GetLightException ( object exceptionValue ) : Exception

Gets the light exception from an object which may contain a light exception. Returns null if the object is not a light exception. Used for throwing the exception at non-light exception boundaries.

IsLightException ( object value ) : bool

Checks to see if the provided value is a light exception.

Rewrite ( Expression expression ) : Expression

Rewrites the provided expression to support light exceptions. Calls to the returned expression, if not from other light-weight aware calls, need to call GetLightException on return to see if an exception was thrown and if so throw it.

RewriteExternal ( Expression expression ) : Expression

Returns a new expression which is re-written for light exceptions but will throw an exception if it escapes the expression. If this expression is part of a larger experssion which is later re-written for light exceptions then it will propagate the light exception up.

RewriteLazy ( Expression expression ) : Expression

Returns a new expression which will lazily reduce to a light expression re-written version of the same expression.

SupportsLightThrow ( this binder ) : bool

Returns true if the call site binder is a light exception binder and supports light throws. Returns false otherwise.

Throw ( Expression exceptionValue ) : Expression

Returns an object which represents a light exception.

Throw ( Expression exceptionValue, Type retType ) : Expression

Returns an object which represents a light exception.

Throw ( this binder, Expression exceptionValue ) : Expression

If the binder supports light exceptions then a light exception throwing expression is returned. Otherwise a normal throwing expression is returned.

Throw ( this binder, Expression exceptionValue, Type retType ) : Expression

If the binder supports light exceptions then a light exception throwing expression is returned. Otherwise a normal throwing expression is returned.

Throw ( Exception exceptionValue ) : object

Returns an object which represents a light exception.

Private Methods

Method Description
ThrowException ( LightException lightEx ) : void
ToReadOnly ( Expression args ) : ReadOnlyCollection

Method Details

CheckAndThrow() public static method

Wraps the expression in a check and rethrow.
public static CheckAndThrow ( Expression expr ) : Expression
expr Expression
return Expression

CheckAndThrow() public static method

Throws the exception if the value represents a light exception
public static CheckAndThrow ( object value ) : object
value object
return object

GetLightException() public static method

Gets the light exception from an object which may contain a light exception. Returns null if the object is not a light exception. Used for throwing the exception at non-light exception boundaries.
public static GetLightException ( object exceptionValue ) : Exception
exceptionValue object
return System.Exception

IsLightException() public static method

Checks to see if the provided value is a light exception.
public static IsLightException ( object value ) : bool
value object
return bool

Rewrite() public static method

Rewrites the provided expression to support light exceptions. Calls to the returned expression, if not from other light-weight aware calls, need to call GetLightException on return to see if an exception was thrown and if so throw it.
public static Rewrite ( Expression expression ) : Expression
expression Expression
return Expression

RewriteExternal() public static method

Returns a new expression which is re-written for light exceptions but will throw an exception if it escapes the expression. If this expression is part of a larger experssion which is later re-written for light exceptions then it will propagate the light exception up.
public static RewriteExternal ( Expression expression ) : Expression
expression Expression
return Expression

RewriteLazy() public static method

Returns a new expression which will lazily reduce to a light expression re-written version of the same expression.
public static RewriteLazy ( Expression expression ) : Expression
expression Expression
return Expression

SupportsLightThrow() public static method

Returns true if the call site binder is a light exception binder and supports light throws. Returns false otherwise.
public static SupportsLightThrow ( this binder ) : bool
binder this
return bool

Throw() public static method

Returns an object which represents a light exception.
public static Throw ( Expression exceptionValue ) : Expression
exceptionValue Expression
return Expression

Throw() public static method

Returns an object which represents a light exception.
public static Throw ( Expression exceptionValue, Type retType ) : Expression
exceptionValue Expression
retType System.Type
return Expression

Throw() public static method

If the binder supports light exceptions then a light exception throwing expression is returned. Otherwise a normal throwing expression is returned.
public static Throw ( this binder, Expression exceptionValue ) : Expression
binder this
exceptionValue Expression
return Expression

Throw() public static method

If the binder supports light exceptions then a light exception throwing expression is returned. Otherwise a normal throwing expression is returned.
public static Throw ( this binder, Expression exceptionValue, Type retType ) : Expression
binder this
exceptionValue Expression
retType System.Type
return Expression

Throw() public static method

Returns an object which represents a light exception.
public static Throw ( Exception exceptionValue ) : object
exceptionValue System.Exception
return object