Monday, February 17, 2020

Exception handling -> "bubble up

Exception handling -> "bubble up"
Exception handling

(#1)


 try
 {
  ...
  // might fail
  ...
 }
 catch (Exception ex)
 {
  ...
  Log(ex);
  throw ex;
 }
where throw ex bubbles the exception up the chain. Creates a new exception to throw - Stack Trace is truncated below the method that failed, no longer have the full stack trace information.

(#2) Compare to

...
catch (Exception ex)
{
 ...
 throw;
}
...
Here throw "rethrows" exception, and Stack trace information is preserved.

So, if (#1) wants to add user-friendly throw new ApplicationException("failed for certain"), then proper way would be throw new ApplicationException("failed for certain", ex)

more at siccolo blurbs

Rotate Array Left N-times c#

Rotate Array Left N-times c#:

public static int[] RotateArrayLeft(int[] ins, int startindex = 1)
 {
  if (ins == null || ins.Length == 0) { return ins; }
  var outs = new int[ins.Length];
  //Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length):
  Array.Copy(ins, startindex, outs, 0, ins.Length - startindex);
  var q = new Queue(ins);
  for (int i = outs.Length - startindex; i < outs.Length; i++)
  {
   outs[i] = q.Dequeue();
  }

  return outs;
 }

more at siccolo blurbs

Shift array

Shift array:

public static int?[] ShiftArray(int?[] ins)
 {
  if (ins == null || ins.Length == 0) { return ins; }
  var outs = new int?[ins.Length];
  Array.Copy(ins, 1, outs, 0, ins.Length - 1);
  outs[outs.Length - 1] = ins[0];
  return outs;
 }

more at siccolo blurbs
manually reverse a string:

 public static string ReverseStringManual(string ins)
 {
  StringBuilder outs = new StringBuilder(ins.Length);
  for (int i = ins.Length; i > 0; i--) { outs.Append(ins[i - 1]); };
  return outs.ToString();
 }

more at siccolo blurbs

Thursday, May 22, 2008

next article in Developing Facebook Application with FBML FBJS FQL and .NET series at CodeProject

see at Developing Facebook Application with .NET - part 2

next article in Developing Facebook Application with FBML FBJS FQL and .NET series

next article in Developing Facebook Application with FBML FBJS FQL and .NET series:


ASP.NET - using FBML Tabs - <fb-tabs/> and <fb:tab-item/> in ASP.NET

ASP.NET - using <fb:request-form/> in ASP.NET

ASP.NET - building Invite page with FBML multi friend selector from ASP.NET

access Facebook Data from ASP.NET (C#) using FQL and DirectFQLQuery()

ASP.NET - update Facebook user profile using SetFBML, <fb:subtitle/>, <fb:wide/> in ASP.NET

ASP.NET - update Facebook user profile using <fb:ref/>, SetRefHandle

ASP.NET - build scheduled updates for Facebook - "cron job" for Facebook using ASP.NET

ASP.NET - populate user profile mini-feed using PublishAction(), Feed.publishActionOfUser using ASP.NET

ASP.NET - handle Application unsintall/remove using Post Remove URL in ASP.NET

Exception handling -> "bubble up

Exception handling -> "bubble up" Exception handling (#1) try { ... // might fail ... } ca...