Guest:
Register
|
Login
|
Member List
|
Search
|
Statistics
|
FAQ
Language
----------
Simplifed Chinese
Traditional Chinese
English
CnPack Forum
»
技术板块灌水区
» [讨论]关于异常
‹‹ Last Thread
|
Next Thread ››
Poll
Trade
Reward
Activity
Printable Version
|
Email to Friend
|
Subscription
|
Favorites
Subject: [讨论]关于异常
jAmEs_
灌水部部长
UID 886
Digest Posts 0
Credits 1134
Posts 600
点点分 1134
Reading Access 10
Registered 2005-6-5
Location 广东
Status Offline
#1
Post at 2007-8-17 17:43
Profile
|
Blog
|
P.M.
[讨论]关于异常
一般情况下,异常都采用
try
except
end;
的形式来截获,但是这样的嵌套多了的情况下,代码越来越难看,又或者我们数据库处理事务时,一般都:
con.BeginTrans();
try
...
con.CommitTrans();
except
con.RollbackTrans();
end;
有没有一种类似这样的方法:
AutoTrans(con);
...
其实主要就是怎么实现在作用域内,AutoTrans可以检测到异常退出调用还是正常退出。
还原探讨~~
Passion
(LiuXiao)
管理员
UID 359
Digest Posts
19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
#2
Post at 2007-8-17 19:46
Profile
|
Blog
|
P.M.
把AutoTrans写成函数,里头用try except
zzzl
(早安的空气)
版主
UID 590
Digest Posts 0
Credits 399
Posts 199
点点分 399
Reading Access 100
Registered 2004-11-29
Status Offline
#3
Post at 2007-8-17 20:11
Profile
|
Blog
|
P.M.
|
同意楼上,把看不顺眼的东西藏起来
jAmEs_
灌水部部长
UID 886
Digest Posts 0
Credits 1134
Posts 600
点点分 1134
Reading Access 10
Registered 2005-6-5
Location 广东
Status Offline
#4
Post at 2007-8-17 21:58
Profile
|
Blog
|
P.M.
QUOTE:
原帖由
Passion
于 2007-8-17 19:46 发表
把AutoTrans写成函数,里头用try except
晕,但是我是希望能通用化啊,你那样还不是一样?
shenloqi
灌水处处长
UID 34
Digest Posts
1
Credits 287
Posts 179
点点分 287
Reading Access 10
Registered 2003-3-15
Status Offline
#5
Post at 2007-8-18 21:08
Profile
|
P.M.
我有一些尝试,用接口的自动引用计数等实现的,不过个人还是觉得不如直接try ... except ... end来的明了
kendling
(小冬)
高级版主
MyvNet
UID 703
Digest Posts
5
Credits 978
Posts 580
点点分 978
Reading Access 101
Registered 2005-2-18
Location 广东
Status Offline
#6
Post at 2007-8-19 01:25
Profile
|
Site
|
Blog
|
P.M.
|
|
对哇,简单的东西不要搞得太复杂。。。
小冬
http://MyvNet.com
jAmEs_
灌水部部长
UID 886
Digest Posts 0
Credits 1134
Posts 600
点点分 1134
Reading Access 10
Registered 2005-6-5
Location 广东
Status Offline
#7
Post at 2007-8-19 14:10
Profile
|
Blog
|
P.M.
其实就是为了简单才这样
你们听说过方面编程吧?我想这个也有这样类似的目的
比如你的代码原来没有这方面的处理,如果要增加,我直接增加一行就行了,但是try except end 则要做比较多的代码处理。
skyjacker
版主
茶农
UID 2239
Digest Posts
9
Credits 617
Posts 269
点点分 617
Reading Access 100
Registered 2006-6-8
Status Offline
#8
Post at 2007-8-19 20:42
Profile
|
Blog
|
P.M.
|
数据库的事务处理可以封装在基类里,这个一个系统中就只有一份代码啦。
一壶清茶煮青春.
bahamut8348
灌水司司长
UID 4743
Digest Posts
14
Credits 337
Posts 79
点点分 337
Reading Access 10
Registered 2007-1-18
Status Offline
#9
Post at 2007-8-29 10:19
Profile
|
Blog
|
P.M.
涉及数据库的"事务",个人建议,像:
con.BeginTrans();
try
...
con.CommitTrans();
except
con.RollbackTrans();
end;
这种语句不建议写在EXE工程里(当然包括DLL),
个人认为,完全可以在SQL(ORCALE)里写一个存储过程,由存储过程控制事务总数和事务的开启、关闭,而在工程里要做的只是调用这个存储过程,并给他传递正确的参数就可以了
做人要厚道,看帖要回贴
Passion
(LiuXiao)
管理员
UID 359
Digest Posts
19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
#10
Post at 2007-8-29 14:25
Profile
|
Blog
|
P.M.
确实写存储过程里头高效不少。
jAmEs_
灌水部部长
UID 886
Digest Posts 0
Credits 1134
Posts 600
点点分 1134
Reading Access 10
Registered 2005-6-5
Location 广东
Status Offline
#11
Post at 2007-8-29 16:20
Profile
|
Blog
|
P.M.
大家讨论的似乎有些跑题了,我只是举例子而已,类似的情况还是有的,而不只是这个。
另外,我说说自己的一些观点,存储过程也有一定的限制,比如调试没那么方便,管理也不一定方便。
Poll
Trade
Reward
Activity
CnPack Forum
CnPack English Forum
> CnWizards IDE Wizards
> CVSTracNT
> Announcements & Others
All times are GMT++8, the time now is 2024-11-24 14:51
Powered by
Discuz!
5.0.0
© 2001-2006
Comsenz Inc.
Processed in 0.008994 second(s), 8 queries , Gzip enabled
TOP
Clear Cookies
-
Contact Us
-
CnPack Website
-
Archiver
-
WAP
Member's CP Home
Edit Profile
Credits Transaction
Public User Groups
Buddy List
Main
Page Views
User Agents
Posts History
Top Forums
Top Threads
Post Ranking
Credit Ranking
Online Time
Team
Moderation Stats