Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 4699409

Browse files
authored
Remove empty try's (#13493)
* Remove empty try's * Remove some dead comments * more
1 parent f4bf920 commit 4699409

File tree

12 files changed

+80
-136
lines changed

12 files changed

+80
-136
lines changed

src/mscorlib/shared/System/DateTime.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,11 +1025,7 @@ public int Month
10251025
}
10261026

10271027
// Returns a DateTime representing the current date and time. The
1028-
// resolution of the returned value depends on the system timer. For
1029-
// Windows NT 3.5 and later the timer resolution is approximately 10ms,
1030-
// for Windows NT 3.1 it is approximately 16ms, and for Windows 95 and 98
1031-
// it is approximately 55ms.
1032-
//
1028+
// resolution of the returned value depends on the system timer.
10331029
public static DateTime Now
10341030
{
10351031
get

src/mscorlib/shared/System/DateTimeOffset.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,7 @@ public DateTimeOffset(int year, int month, int day, int hour, int minute, int se
129129
}
130130

131131
// Returns a DateTimeOffset representing the current date and time. The
132-
// resolution of the returned value depends on the system timer. For
133-
// Windows NT 3.5 and later the timer resolution is approximately 10ms,
134-
// for Windows NT 3.1 it is approximately 16ms, and for Windows 95 and 98
135-
// it is approximately 55ms.
136-
//
132+
// resolution of the returned value depends on the system timer.
137133
public static DateTimeOffset Now
138134
{
139135
get

src/mscorlib/shared/System/IO/FileStream.Windows.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,8 @@ private unsafe void WriteCore(byte[] buffer, int offset, int count)
742742
else
743743
{
744744
// ERROR_INVALID_PARAMETER may be returned for writes
745-
// where the position is too large (i.e. writing at Int64.MaxValue
746-
// on Win9x) OR for synchronous writes to a handle opened
747-
// asynchronously.
745+
// where the position is too large or for synchronous writes
746+
// to a handle opened asynchronously.
748747
if (errorCode == ERROR_INVALID_PARAMETER)
749748
throw new IOException(SR.IO_FileTooLongOrHandleNotSync);
750749
throw Win32Marshal.GetExceptionForWin32Error(errorCode);

src/mscorlib/src/Microsoft/Win32/RegistryKey.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,7 @@ public Object GetValue(String name)
458458
* Note that <var>name</var> can be null or "", at which point the
459459
* unnamed or default value of this Registry key is returned, if any.
460460
* The default values for RegistryKeys are OS-dependent. NT doesn't
461-
* have them by default, but they can exist and be of any type. On
462-
* Win95, the default value is always an empty key of type REG_SZ.
463-
* Win98 supports default values of any type, but defaults to REG_SZ.
461+
* have them by default, but they can exist and be of any type.
464462
*
465463
* @param name Name of value to retrieve.
466464
* @param defaultValue Value to return if <i>name</i> doesn't exist.

src/mscorlib/src/System/Diagnostics/Stacktrace.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,6 @@ private void OnDeserialized(StreamingContext context)
247247

248248
// Class which represents a description of a stack trace
249249
// There is no good reason for the methods of this class to be virtual.
250-
// In order to ensure trusted code can trust the data it gets from a
251-
// StackTrace, we use an InheritanceDemand to prevent partially-trusted
252-
// subclasses.
253250
public class StackTrace
254251
{
255252
private StackFrame[] frames;

src/mscorlib/src/System/Environment.cs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -241,44 +241,38 @@ private unsafe static char[] GetEnvironmentCharArray()
241241
{
242242
char[] block = null;
243243

244-
// Make sure pStrings is not leaked with async exceptions
245244
RuntimeHelpers.PrepareConstrainedRegions();
245+
246+
char* pStrings = null;
247+
246248
try
247249
{
248-
}
249-
finally
250-
{
251-
char* pStrings = null;
252-
253-
try
250+
pStrings = Win32Native.GetEnvironmentStrings();
251+
if (pStrings == null)
254252
{
255-
pStrings = Win32Native.GetEnvironmentStrings();
256-
if (pStrings == null)
257-
{
258-
throw new OutOfMemoryException();
259-
}
253+
throw new OutOfMemoryException();
254+
}
260255

261-
// Format for GetEnvironmentStrings is:
262-
// [=HiddenVar=value\0]* [Variable=value\0]* \0
263-
// See the description of Environment Blocks in MSDN's
264-
// CreateProcess page (null-terminated array of null-terminated strings).
256+
// Format for GetEnvironmentStrings is:
257+
// [=HiddenVar=value\0]* [Variable=value\0]* \0
258+
// See the description of Environment Blocks in MSDN's
259+
// CreateProcess page (null-terminated array of null-terminated strings).
265260

266-
// Search for terminating \0\0 (two unicode \0's).
267-
char* p = pStrings;
268-
while (!(*p == '\0' && *(p + 1) == '\0'))
269-
p++;
261+
// Search for terminating \0\0 (two unicode \0's).
262+
char* p = pStrings;
263+
while (!(*p == '\0' && *(p + 1) == '\0'))
264+
p++;
270265

271-
int len = (int)(p - pStrings + 1);
272-
block = new char[len];
266+
int len = (int)(p - pStrings + 1);
267+
block = new char[len];
273268

274-
fixed (char* pBlock = block)
275-
string.wstrcpy(pBlock, pStrings, len);
276-
}
277-
finally
278-
{
279-
if (pStrings != null)
280-
Win32Native.FreeEnvironmentStrings(pStrings);
281-
}
269+
fixed (char* pBlock = block)
270+
string.wstrcpy(pBlock, pStrings, len);
271+
}
272+
finally
273+
{
274+
if (pStrings != null)
275+
Win32Native.FreeEnvironmentStrings(pStrings);
282276
}
283277

284278
return block;

src/mscorlib/src/System/Reflection/RuntimeConstructorInfo.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ internal INVOCATION_FLAGS InvocationFlags
5757
// this should be an invocable method, determine the other flags that participate in invocation
5858
invocationFlags |= RuntimeMethodHandle.GetSecurityFlags(this);
5959

60-
// Check for attempt to create a delegate class, we demand unmanaged
61-
// code permission for this since it's hard to validate the target address.
60+
// Check for attempt to create a delegate class.
6261
if (typeof(Delegate).IsAssignableFrom(DeclaringType))
6362
invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_IS_DELEGATE_CTOR;
6463
}

src/mscorlib/src/System/Runtime/InteropServices/CriticalHandle.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,7 @@ with the following type of signature (CreateFile follows this model).
130130

131131
namespace System.Runtime.InteropServices
132132
{
133-
// This class should not be serializable - it's a handle. We require unmanaged
134-
// code permission to subclass CriticalHandle to prevent people from writing a
135-
// subclass and suddenly being able to run arbitrary native code with the
136-
// same signature as CloseHandle. This is technically a little redundant, but
137-
// we'll do this to ensure we've cut off all attack vectors. Similarly, all
138-
// methods have a link demand to ensure untrusted code cannot directly edit
139-
// or alter a handle.
133+
// This class should not be serializable - it's a handle
140134
public abstract class CriticalHandle : CriticalFinalizerObject, IDisposable
141135
{
142136
// ! Do not add or rearrange fields as the EE depends on this layout.

src/mscorlib/src/System/Runtime/InteropServices/SafeBuffer.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,10 @@ public void AcquirePointer(ref byte* pointer)
173173

174174
pointer = null;
175175
RuntimeHelpers.PrepareConstrainedRegions();
176-
try
177-
{
178-
}
179-
finally
180-
{
181-
bool junk = false;
182-
DangerousAddRef(ref junk);
183-
pointer = (byte*)handle;
184-
}
176+
177+
bool junk = false;
178+
DangerousAddRef(ref junk);
179+
pointer = (byte*)handle;
185180
}
186181

187182
public void ReleasePointer()

src/mscorlib/src/System/Runtime/MemoryFailPoint.cs

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,20 @@ public MemoryFailPoint(int sizeInMegabytes)
241241
// Attempt to grow the OS's page file. Note that we ignore
242242
// any allocation routines from the host intentionally.
243243
RuntimeHelpers.PrepareConstrainedRegions();
244-
try
245-
{
246-
}
247-
finally
244+
245+
// This shouldn't overflow due to the if clauses above.
246+
UIntPtr numBytes = new UIntPtr(segmentSize);
247+
unsafe
248248
{
249-
// This shouldn't overflow due to the if clauses above.
250-
UIntPtr numBytes = new UIntPtr(segmentSize);
251-
unsafe
249+
void* pMemory = Win32Native.VirtualAlloc(null, numBytes, Win32Native.MEM_COMMIT, Win32Native.PAGE_READWRITE);
250+
if (pMemory != null)
252251
{
253-
void* pMemory = Win32Native.VirtualAlloc(null, numBytes, Win32Native.MEM_COMMIT, Win32Native.PAGE_READWRITE);
254-
if (pMemory != null)
255-
{
256-
bool r = Win32Native.VirtualFree(pMemory, UIntPtr.Zero, Win32Native.MEM_RELEASE);
257-
if (!r)
258-
__Error.WinIOError();
259-
}
252+
bool r = Win32Native.VirtualFree(pMemory, UIntPtr.Zero, Win32Native.MEM_RELEASE);
253+
if (!r)
254+
__Error.WinIOError();
260255
}
261256
}
257+
262258
continue;
263259

264260
case 2:
@@ -304,14 +300,9 @@ public MemoryFailPoint(int sizeInMegabytes)
304300
CheckForFreeAddressSpace(segmentSize, true);
305301

306302
RuntimeHelpers.PrepareConstrainedRegions();
307-
try
308-
{
309-
}
310-
finally
311-
{
312-
SharedStatics.AddMemoryFailPointReservation((long)size);
313-
_mustSubtractReservation = true;
314-
}
303+
304+
SharedStatics.AddMemoryFailPointReservation((long)size);
305+
_mustSubtractReservation = true;
315306
#endif
316307
}
317308

@@ -414,14 +405,9 @@ private void Dispose(bool disposing)
414405
if (_mustSubtractReservation)
415406
{
416407
RuntimeHelpers.PrepareConstrainedRegions();
417-
try
418-
{
419-
}
420-
finally
421-
{
422-
SharedStatics.AddMemoryFailPointReservation(-((long)_reservedMemory));
423-
_mustSubtractReservation = false;
424-
}
408+
409+
SharedStatics.AddMemoryFailPointReservation(-((long)_reservedMemory));
410+
_mustSubtractReservation = false;
425411
}
426412

427413
/*

src/mscorlib/src/System/Runtime/Reliability/CriticalFinalizerObject.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
** (i.e. the finalizer is guaranteed to run, won't be aborted by the host and is
1212
** run after the finalizers of other objects collected at the same time).
1313
**
14-
** You must possess UnmanagedCode permission in order to derive from this class.
1514
**
1615
**
1716
===========================================================*/

src/mscorlib/src/System/Threading/ThreadPool.cs

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -790,16 +790,11 @@ internal void SetWaitObject(WaitHandle waitObject)
790790
{
791791
// needed for DangerousAddRef
792792
RuntimeHelpers.PrepareConstrainedRegions();
793-
try
793+
794+
m_internalWaitObject = waitObject;
795+
if (waitObject != null)
794796
{
795-
}
796-
finally
797-
{
798-
m_internalWaitObject = waitObject;
799-
if (waitObject != null)
800-
{
801-
m_internalWaitObject.SafeWaitHandle.DangerousAddRef(ref bReleaseNeeded);
802-
}
797+
m_internalWaitObject.SafeWaitHandle.DangerousAddRef(ref bReleaseNeeded);
803798
}
804799
}
805800

@@ -810,47 +805,43 @@ WaitHandle waitObject // object to be notified when all callbacks to de
810805
bool result = false;
811806
// needed for DangerousRelease
812807
RuntimeHelpers.PrepareConstrainedRegions();
813-
try
814-
{
815-
}
816-
finally
808+
809+
// lock(this) cannot be used reliably in Cer since thin lock could be
810+
// promoted to syncblock and that is not a guaranteed operation
811+
bool bLockTaken = false;
812+
do
817813
{
818-
// lock(this) cannot be used reliably in Cer since thin lock could be
819-
// promoted to syncblock and that is not a guaranteed operation
820-
bool bLockTaken = false;
821-
do
814+
if (Interlocked.CompareExchange(ref m_lock, 1, 0) == 0)
822815
{
823-
if (Interlocked.CompareExchange(ref m_lock, 1, 0) == 0)
816+
bLockTaken = true;
817+
try
824818
{
825-
bLockTaken = true;
826-
try
819+
if (ValidHandle())
827820
{
828-
if (ValidHandle())
821+
result = UnregisterWaitNative(GetHandle(), waitObject == null ? null : waitObject.SafeWaitHandle);
822+
if (result == true)
829823
{
830-
result = UnregisterWaitNative(GetHandle(), waitObject == null ? null : waitObject.SafeWaitHandle);
831-
if (result == true)
824+
if (bReleaseNeeded)
832825
{
833-
if (bReleaseNeeded)
834-
{
835-
m_internalWaitObject.SafeWaitHandle.DangerousRelease();
836-
bReleaseNeeded = false;
837-
}
838-
// if result not true don't release/suppress here so finalizer can make another attempt
839-
SetHandle(InvalidHandle);
840-
m_internalWaitObject = null;
841-
GC.SuppressFinalize(this);
826+
m_internalWaitObject.SafeWaitHandle.DangerousRelease();
827+
bReleaseNeeded = false;
842828
}
829+
// if result not true don't release/suppress here so finalizer can make another attempt
830+
SetHandle(InvalidHandle);
831+
m_internalWaitObject = null;
832+
GC.SuppressFinalize(this);
843833
}
844834
}
845-
finally
846-
{
847-
m_lock = 0;
848-
}
849835
}
850-
Thread.SpinWait(1); // yield to processor
836+
finally
837+
{
838+
m_lock = 0;
839+
}
851840
}
852-
while (!bLockTaken);
841+
Thread.SpinWait(1); // yield to processor
853842
}
843+
while (!bLockTaken);
844+
854845
return result;
855846
}
856847

0 commit comments

Comments
 (0)