Journey of Luke sky walker.
Title
Start Game
Mini movie
Platform
Aug 13, 2007
Design Exception Handler Pattern
When we write application we should handle exception for block Application Exception when it occurs, our application may crash.
.Net developer regular design exception as this.
Try
‘statement for operation
‘statement for operation
‘e.g’
Dim CN as new Oledb.OledbConnection(strConnectionString)
CN.Open()
‘other statement for operation
Catch ex as Exception
‘statement for handler exception
‘e.g.
ModuleLogError.WriteLog(ex)
Finally
‘This statement will execute even code have exception or not
CN.Close
End try
This rule will help for design better structure of handle exception.
1. Check exception may occur before Exception
e.g. DivideByZeroException,ArithmeticException …
This below is a sample code
Try
‘’’
Catch(Ex as DivideByZeroException)
‘’’
Catch(Ex as ArithmeticException)
‘’’
Catch(Ex as Exception)
‘’’
End Try
2. Keep module detail to have occur exception
In a moudule we handler exception we shuld send information about module have occure exception e.g. Modulename,section of section
Dim strModuleName as string= “DAC.Customer” ‘This variable outside method because we shared it multiple method
Private Sub SaveData()
Dim strMethodName as string=”SaveData”
Dim strSection as string = “Begin Module”
Try
strSection = “Operation 1”
‘statement for operation1
strSection = “Operation 2”
‘statement for operation2
‘other statement for operation
Catch ex as Exception
ModuleLogError.WriteLog(ex,strModuleName,strMethodName,strSection,)
Finally
‘This statement will execute even code have exception or not
CN.Close
End try
End Sub
3. When we loop operation loop should in exception
e.g.
if your code is look like this:
dim I as integer
for I = 1 to 100
Try
‘statement
Catch ex as Exception
‘statement for handler
Finally
‘statement for release unsafe resource and other benefits
End try
next
It should refractor your code as below:
Try
Dim I as integer
For I = 1 to 100
‘statement
Next
Catch ex as Exception
‘statement for handler
Finally
‘statement for release unsafe resource and other benefits
End try
It is have high performance than before.
4. Avoid use exception in case we can handle it by operation checking
e.g.
if(Num1 = 0) then
MessageBox.show(“Value cannot be 0”)
Exit sub
end if
dim dblResult = Num2 / Num1
instead
try
Dim dblResult = Num2 / Num1
Catch ex as DivideByZeroException{
MessageBox.Show(“Value cannot be 0”)
End Try
Because exception is expensive, we should avoid in a case we can handle it
5.When you application design for contact with another layer (some dll ,e.g. BC layer, DAC layer) you may not throw exception, but should keep exception for client to handle it.
e.g
This is a DAC.
Namespace DAC
Public Class Customer
Dim currentException as ApplicationException
Public Sub AddData()
Try
‘’’ Statement
Catch Ex as Exception
Me.CurrentException = Ex
End Try
End Sub
End Class
End NameSpace
And this is a client code.
Dim cCustomer as New DAC.Customer
cCustomer.AddData
if(Not isnothing(cCustomer.currentException ))
‘code for handler exception of dac
‘e.g.
‘MessageBox.Show(ex.Tostring) ‘ for winform
‘Me.lblShowError.InnerText = ex.ToString ‘for web form
‘code for write log error
End if
6. In development phase you should display detail about exception instead hardcode wording for user
e.g.
Try
‘Code for Add data
Catch Ex as Exception
MessageBox.show(ex.toString)
Instead
MessageBox.show(“Error:Please enter againg”)
End Try
This will help you easy to find the problem, and then you pass development phase you may change wording to friendly word for user. Or you may send both error message and friendly word to user , but you should care about security issue.
7. Desing your own exception
If you wish to design you exception. It is easy to do, you just create a new class and inherit from ApplicationException
Posted by
DevGod
at
9:38:00 PM
0
comments
Labels: .Net
Aug 9, 2007
Aug 7, 2007
Classic Game 12 RockMan3
This is third adventure of rockman on nes platform.
In america this game call "megaman 3"
This adventure we must fight with DR.Willy as previous, and we got rush a dog robot for assistant you for beat with your enemy.
Title
Boss
Battle field
Posted by
DevGod
at
10:57:00 PM
2
comments
Labels: classic game
Aug 6, 2007
Classic Game 11 Donkey Kong III
You are Dixie Kong and Kiddie Kong journey for a new adventure.
As a previous journey you must beat a King K. Rool again.
and in this adventure you will meet numbers of friend.
King K. Rool
This image is original from wikipedia.
Posted by
DevGod
at
10:21:00 PM
0
comments
Labels: classic game
Aug 5, 2007
Ajax Tabcontrol inside Update panel can't find CSS
I use Ajax Tabcontrol inside Updatepanel
and each tabcontrol contain Usercontrol
each Usercontrol reference CSS file
when first run It fine.
but when I update data.
Page display is crash.
I found solutino fo solve this problem
you just copy code for reference to css file in usercontrol
to page
Posted by
DevGod
at
11:32:00 PM
0
comments
How i hide left navigate and right navigate YUI Calendar ?
In my project i must use YUI Calendar control for build static calendar show to user.
but I can't find the solution to hide left navigate and right navigate.
after i search yahoo api , I don't found any thing.
but now,after i try to hack calendar.js
I know the solution for hide left navigator and right navigator
First solution
1.Open calendar.js this file is in yui2.3.0\yui\build\calendar\
2.you just go to line 2321 and you will see javascript code for about render left and right navigator
then you just comment this code
you must separate comment to two group because you should not comment code for display month name
/*
if (renderLeft) {
var leftArrow = this.cfg.getProperty(defCfg.NAV_ARROW_LEFT.key);
// Check for deprecated customization - If someone set IMG_ROOT, but didn't set NAV_ARROW_LEFT, then set NAV_ARROW_LEFT to the old deprecated value
if (leftArrow === null && YAHOO.widget.Calendar.IMG_ROOT !== null) {
leftArrow = YAHOO.widget.Calendar.IMG_ROOT + DEPR_NAV_LEFT;
}
var leftStyle = (leftArrow === null) ? "" : ' style="background-image:url(' + leftArrow + ')"';
html[html.length] = ' ';
}
*/
html[html.length] = this.buildMonthLabel(); /* This line is for display Month don't comment it */
/*
if (renderRight) {
var rightArrow = this.cfg.getProperty(defCfg.NAV_ARROW_RIGHT.key);
if (rightArrow === null && YAHOO.widget.Calendar.IMG_ROOT !== null) {
rightArrow = YAHOO.widget.Calendar.IMG_ROOT + DEPR_NAV_RIGHT;
}
var rightStyle = (rightArrow === null) ? "" : ' style="background-image:url(' + rightArrow + ')"';
html[html.length] = ' ';
}
*/
3.and then you just save calendar.js when you create Calendar you don't see left navigate button and right navigate button.
But this solution will make all of calendar of your app don't display left and right navigate button except you will separate calendar.js.
well I think we shoul have a better solution
Lets'go to second solution
Second solution.
1.like first solution.You just open calendar.js
2.you just set id of both left and right navgate button in this case I name ALeft and ARight.
if (renderLeft) {
var leftArrow = this.cfg.getProperty(defCfg.NAV_ARROW_LEFT.key);
// Check for deprecated customization - If someone set IMG_ROOT, but didn't set NAV_ARROW_LEFT, then set NAV_ARROW_LEFT to the old deprecated value
if (leftArrow === null && YAHOO.widget.Calendar.IMG_ROOT !== null) {
leftArrow = YAHOO.widget.Calendar.IMG_ROOT + DEPR_NAV_LEFT;
}
var leftStyle = (leftArrow === null) ? "" : ' style="background-image:url(' + leftArrow + ')"';
html[html.length] = ' ';
}
html[html.length] = this.buildMonthLabel();
if (renderRight) {
var rightArrow = this.cfg.getProperty(defCfg.NAV_ARROW_RIGHT.key);
if (rightArrow === null && YAHOO.widget.Calendar.IMG_ROOT !== null) {
rightArrow = YAHOO.widget.Calendar.IMG_ROOT + DEPR_NAV_RIGHT;
}
var rightStyle = (rightArrow === null) ? "" : ' style="background-image:url(' + rightArrow + ')"';
html[html.length] = ' ';
}
3.In a page you wish build calendar and wish to hide left and right navigator.
you just write this code
I use setTimeout because I want to object calendar loaded.
when first excute function HideNav if element ALeft or ARight dosen't loaded.
it will setTimeout again and again until ALeft and ARigh loaded and hide it.
Now.I think this solution work for me.
But you may have a problem.
e.g. When your page have more than one calendar and you want to hide navigate button of some calendar.and now each navigator button have same id (ALeft and ARight)
Posted by
DevGod
at
11:30:00 PM
1 comments

