Throwing or catching exception strategy on building an application is a very important to get detail exception message, inner exception and detail strack trace where or which part of line of code that fired the exception.
The following snipped code shows how to extract detail exception message, innner excepion and its detail strack trace to be recorded / written on log.
/// <summary>/// Extracting <seealso cref="System.Exception"> class include its inner exception/// </seealso></summary>publicsealedclassExtractor{/// <summary>/// Parse the specified ex./// </summary>/// <param name="exception">Ex.publicstaticstringParse(System.Exceptionexception){stringerrMessage=Environment.NewLine;errMessage+=FormatErrorDescription(exception);while(exception.InnerException!=null){errMessage+=ExtractInnerException(exception.InnerException);exception=exception.InnerException;}errMessage+=Environment.NewLine;returnerrMessage;}/// <summary>/// Extract exception message and its strack trace/// </summary>/// <param name="innerException">inner excepion object/// <returns>extracted exception info including message and strack trace</returns>staticstringExtractInnerException(System.ExceptioninnerException){stringerrMessage=string.Empty;errMessage+=Environment.NewLine+" InnerException ";errMessage+=FormatErrorDescription(innerException);returnerrMessage;}/// <summary>/// Formating exception description format/// </summary>/// <param name="exception">/// <returns>Error description</returns>staticstringFormatErrorDescription(System.Exceptionexception){if(exception==null)returnstring.Empty;returnEnvironment.NewLine+exception.Message+Environment.NewLine+exception.StackTrace;}}
I used to got a need to build small and simple plugin for Excel using VSTO. But I won’t write about VSTO in this post. The thing that I want to share is just a simple code to get excel column name by index and vise versa. I felt it was very important for me cause I worked intensively with index at that project.
publicclassExcelUtility{/// <summary>/// Convert Excel column name into number/index. Column number start from 1. A equal to 1/// </summary>/// <param name="columnName">Column name/// <returns>Excel column in numeric</returns>publicstaticintGetExcelColumnNumber(stringcolumnName){if(string.IsNullOrEmpty(columnName))thrownewArgumentNullException("Invalid column name parameter");columnName=columnName.ToUpperInvariant();intsum=0;charch;for(inti=0;i<columnName.Length;i++){ch=columnName[i];if(char.IsDigit(ch))thrownewArgumentNullException("Invalid column name parameter on character "+ch);sum*=26;sum+=(ch-'A'+1);//sum += (columnName[i] - 'A');}returnsum;}/// <summary>/// Convert Excel column index into name. Column start from 1/// </summary>/// <param name="columnNumber">Column name/number/// <returns>Column name</returns>publicstaticstringGetExcelColumnName(intcolumnNumber){intdividend=columnNumber;stringcolumnName=String.Empty;intmodulo;while(dividend>0){modulo=(dividend-1)%26;columnName=Convert.ToChar(65+modulo).ToString()+columnName;dividend=(int)((dividend-modulo)/26);}returncolumnName;}}
classProgram{staticvoidMain(string[]args){try{stringcolumnName="A";intcolumnIndex=ExcelUtility.GetExcelColumnNumber(columnName);Console.WriteLine("Index of {0} is {1} ",columnName,columnIndex);//increment columnIndex++columnIndex;Console.WriteLine("Increment index = "+columnIndex);columnName=ExcelUtility.GetExcelColumnName(columnIndex);Console.WriteLine("Column name of index {0} is {1}",columnIndex,columnName);}catch(Exceptionex){Console.WriteLine(ex.Message);}Console.Read();}}
I write the code in my blog just to remind me in the future in case I get the same need. And it would be great if it can help others who have the same need as me :)
Xamarin Studio is a great Mono IDE (Integrated Development Environment) in OS X area. At the time of writing this article, the version of Xamarin studio and mono framework I use are :
Xamarin Studio
Version 4.2.1 (build 1)
Runtime:
Mono 3.2.5 ((no/964e8f0)
GTK+ 2.24.20 theme: Raleigh
GTK# (2.12.0.0)
Package version: 302050000
Xamarin Studio includes with ASP.NET MVC 2 and 3 project template. While trying to create ASP.NET MVC 3 project, I got couples of errors such as authorization access etc. The good news is even though there is no project template for ASP.NET MVC 4, we still can convert our ASP.NET MVC 3 to run as ASP.NET MVC 4. The steps are :
Create an ASP.NET MVC 3 project either with aspx or razor view engine
Run the project via Xamarin studio menu (Run > Run With > Mono Soft Debugger for ASP.NET. While running the project, we may got an error message :
To solve the error, run the following command in terminal :
</code>
Re-run again the ASP.NET MVC project. We may get another error message.
To solve the error message, just use NuGet package manager, search for “ASP.NET MVC 4″ and add reference to it and its dependencies.
Re-run the ASP.NET MVC again. Now we may get another error message as following :
As the error message, we need to make our ASP.NET Web Pages version to 2.0.0.0 in web.config. So just open web.config and change webpages:Version to 2.0.0.0. as follow :
Change assembly version declared in root web.config and /View/web.config of the following
assembly
from
to
System.Web.WebPages.Razor
1.0.0.0
2.0.0.0
System.Web.Mvc
3.0.0.0
4.0.0.0
Now re-run the project again via Xamarin Studio and our project should run well as expected.
The following day after the release of iOS 7, I started update my iphone 4s to get to know how exactly the ios 7 is. My iphone successfully updated even though it was quite annoying with slow internet connection :( .
The next thing is updating my Xcode, since I got a notification to update my xcode from version 4.6.3 to version 5.0 via app store of version 1.2.2. My OSX version is 10.8.5.
While updatig process, several times I got error message Xcode failed to download use the purchases page to try again, and my download prosess suddenly stopped. Googling on internet and asking forum got many different suggestion and solution. Thankfully one of them success that is by clearing appstore download cache.
The steps to get things to work are quite simple.
Keep the AppStore App open. Open terminal and type
``` bash
cd /private/var/folders/
```
Once there, search for com.apple.appstore
``` bash
find . | grep com.apple.appstore
```
You will find folder structure like this ./40/lhn22jn901zdw2bpf82hkggw0000gn/C/com.apple.appstore
Once inside the folder, open it in finder
``` bash
open .
```
While keeping AppStore open, remove this folder
``` bash
rm -rf *
```
Now, go back to AppStore and click on Download again.
If download/update disappear, close the appstore then reopen it.
That steps worked well to me. Good luck and have a nice day.
I often got annoying pup up error message. An internal error occurred during updating Maven project. The message was Unsupported IClasspathEntry kind=…
Googling for that problem finally got a trick how to resolve it.
Right-click on your project, select Maven > Disable Maven Nature
Open your terminal, go to your project folder and do
Right click on your Project and select Configure > Convert into Maven Project
After converting into maven project, I can update my maven project and everything running well :)