Posts

Throw your own - Custom Exceptions

The key to understanding custom exception concept lies in knowing how to catch them. You have to know syntax, and you have to know how to use it. First, the syntax itself try {} catch (CustomException $e) {} catch (OtherException $e) {} catch (Exception $e) {} Basicaly it looks like an switch/case statement. The above code could be written as the next one, and all will be valid and will work perfectly. The try catch syntax is actually automatically handled multiple if statement! try {} catch (Exception $e) { if ($e instanceof CustomException) {} else if ($e instanceof OtherException) {} else {} } Throw your own Note that by distinguishing exceptions you can decide which are the fatal errors and which exceptions are only passing you an information that something is wrong and it is a handled case. This means that you have to use Exceptions not only on critical situations. Throw them for your handled situations too. class MyAuthException extends Exception {} class MyTest { pri...

Throw your own - Losing the fear of Exceptions

The best way to lose the fear of exceptions is to start throwing them. Recipe is simple: whenever you come to case that something is wrong and your function or method can not accomplish its task, just throw an exception. Example 1 My favorite case is when I'm using a configuration values in my applications. Ops, there is no value at all, not an numeric value? I'll just throw an exception and stop thinking about that. This case is especially important if your application will have several installations. This way you are ensuring that nobody (including you) can not forget to fill in configuration. Or, when such case happen anyway, problem will be immediately identified. class MyIni { private $_config; public function __construct( $config) { $this->_config = $config; } public function getProductId() { if (!isset($this->_config['productId'])) throw new Exception( 'Required config parameter [productId] is not set'); if (!is_numeric( $this...

Starting a Thread targeting method with parameters

Lets say you want to start a thread. How would you do it? Thread  T1 =  new   Thread ( new   ParameterizedThreadStart (SomeMethodName)); Restriction imposed by .NET is that Method which T1 targets can have only one parameter of object type. Hence, above code will work only if method signature is: public   static   void  SomeMethodName( object  o) But what if I want to invoke a method like: public   static   void  xyz ( int  a,  int  b) ??? Answer is to use delegates here and start thread as: Thread  T3 =  new   Thread ( delegate () { xyz(3, 4); }); or Thread  T3 =  new   Thread (() => xyz(3, 4));

The following module was built either with optimizations enabled or without debug information Visual Studio

Image
If you are facing this issue for long you must be on verge of banging your head or throw away your PC. There are many cause for this error. You might have tried options and may have missed a few. Following is a summary of different things that have helped me in resolving this issue (Hope it helps you out too): 1. In your Visual Studio, Go to Tools>Options>Debugging>General and check "Enable just my code as shown below" 2. If your application is configured to run using a IIS URL instead of dynamic localhost port, just ensure that IIS directory is pointing to your directory. Often while testing we make different copies of application and keep pointing application in IIS to one or the other. This actually resolved my issue. 3. Clean your solution, close VS, open again, rebuild application and try 4.Open properties of your project and ensure configuration as below: 5. Continuing from above, press advance button in Build settings below which opens a popup. Ensure, Debug I...

Delete network credential from IE

If you have mistakenly opted for "remember password" while opening sharepoint site (or any other site which opens a popup up for network credentials), then forcing IE to again start prompting for credentials is a pain unless you know the right think to do. Everywhere you will get replies to delete cookies and other files by going into IE8>Settings>Content>AutoComplete>Delete Files. But this doesn't works for network credentials as they actually get stored by windows. Instead do following: STEPS (applies to windows 7) 1. Click on start button 2. Type passwords and select Manage network passwords option from filtered list.      You will find saved URLs and passwords of saved credentials 3. Select Delete option for the saved credential you want to remove

disabling Page Cache

1. Create a new .cs file "MyHttpModule.cs"      public   class MyHttpModule :  IHttpModule     {          public   void  Dispose()         {                      }          public   void  Init( HttpApplication  context)         {            context.PostRequestHandlerExecute += new   EventHandler (context_PostRequestHandlerExecute);         }          public   void  context_PostRequestHandlerExecute( object  sender,  EventArgs  e)         {  ...

Latest Javascript framework tags

Image
Get latest javascript framework links from http://scriptsrc.net/