singrdk/base/Applications/Runtime/Full/System/Exception.cs

158 lines
5.0 KiB
C#
Raw Permalink Normal View History

2008-03-05 09:52:00 -05:00
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
2008-11-17 18:29:00 -05:00
//=============================================================================
//
// Class: Exception
//
// Purpose: The base class for all exceptional conditions.
//
//=============================================================================
namespace System
{
2008-03-05 09:52:00 -05:00
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using System.Text;
using System.Reflection;
#if SINGULARITY_KERNEL
using Microsoft.Singularity;
#elif SINGULARITY_PROCESS
using Microsoft.Singularity.V1.Services;
#endif // SINGULARITY_PROCESS
//| <include path='docs/doc[@for="Exception"]/*' />
2008-11-17 18:29:00 -05:00
[AccessedByRuntime("referenced from halexn.cpp")]
public partial class Exception
2008-03-05 09:52:00 -05:00
{
//| <include path='docs/doc[@for="Exception.Exception"]/*' />
public Exception() {
_message = null;
#if SINGULARITY_KERNEL
//DebugStub.Break();
#elif SINGULARITY_PROCESS
//DebugService.Break();
#endif // SINGULARITY_PROCESS
}
// Creates a new Exception. All derived classes should
// provide this constructor.
// Note: the stack trace is not started until the exception
// is thrown
//
//| <include path='docs/doc[@for="Exception.Exception2"]/*' />
public Exception (String message, Exception innerException)
{
// TODO: The innerException will be provided by the runtime
// in the M9 time frame. Until then, we need this method.
_message = message;
_innerException = innerException;
}
//| <include path='docs/doc[@for="Exception.Message"]/*' />
public virtual String Message {
get {
if (_message == null) {
return "Exception_WasThrown";
2008-11-17 18:29:00 -05:00
}
else {
2008-03-05 09:52:00 -05:00
return _message;
}
}
}
private String GetClassName() {
return this.vtable.vtableType.FullName;
}
// Retrieves the lowest exception (inner most) for the given Exception.
// This will traverse exceptions using the innerException property.
//
//| <include path='docs/doc[@for="Exception.GetBaseException"]/*' />
public virtual Exception GetBaseException()
{
Exception inner = InnerException;
Exception back = this;
while (inner != null) {
back = inner;
inner = inner.InnerException;
}
return back;
}
// Returns the inner exception contained in this exception
//
//| <include path='docs/doc[@for="Exception.InnerException"]/*' />
public Exception InnerException {
get { return _innerException; }
}
//| <include path='docs/doc[@for="Exception.ToString"]/*' />
public override String ToString() {
String message = Message;
2008-11-17 18:29:00 -05:00
if (_innerException != null) {
2008-03-05 09:52:00 -05:00
message = message + " ---> " + _innerException.ToString() + "\r\n" + " " + "Exception_EndOfInnerExceptionStack";
}
return message;
}
[AccessedByRuntime("referenced from halasm.asm")]
internal static unsafe bool IsUnlinkStack(UIntPtr throwAddr) {
UIntPtr unlinkBegin;
UIntPtr unlinkLimit;
2008-11-17 18:29:00 -05:00
fixed (byte *begin = &Microsoft.Singularity.Memory.Stacks.LinkStackBegin) {
2008-03-05 09:52:00 -05:00
unlinkBegin = (UIntPtr)begin;
}
2008-11-17 18:29:00 -05:00
fixed (byte *limit = &Microsoft.Singularity.Memory.Stacks.LinkStackLimit) {
2008-03-05 09:52:00 -05:00
unlinkLimit = (UIntPtr)limit;
}
2008-11-17 18:29:00 -05:00
if (throwAddr >= unlinkBegin && throwAddr <= unlinkLimit) {
2008-03-05 09:52:00 -05:00
return true;
2008-11-17 18:29:00 -05:00
}
else {
2008-03-05 09:52:00 -05:00
return false;
}
}
// This is the function that users can override
// BUGBUG: provide a better default (probably deep copy). The
// current one does not deal with references well, and so, is
// not even a good shallow copy (it should at least null out the
// references).
virtual protected Exception cloneForUndo() {
return (Exception)this.MemberwiseClone();
}
[AccessedByRuntime("referenced from halexn.cpp")]
internal String _message;
private Exception _innerException;
[AccessedByRuntime("referenced from halexn.cpp")]
private UIntPtr _throwAddress;
[AccessedByRuntime("referenced from halexn.cpp")]
private bool _notifiedDebugger; // True if debugger first chance already thrown.
2008-11-17 18:29:00 -05:00
// [Bartok]:
2008-03-05 09:52:00 -05:00
public string StackTrace
{
get {
return "<no.stack.trace>";
}
}
}
}