Pls clarify

G

Gopal Prabhakaran

Dear Guys

Equalant to OnError Resume Next in .net

My problem is : if error is found, it must contiune from next line. Like
OnError Resume Next in vb

Thanx
Gopal Prabhakaran
 
P

Peter Rilling

The only way to do this is to wrap each statement that might throw an
exception in its own try...catch block with an empty catch statement.
 
G

Gopal Prabhakaran

Dear Peter Rilling

pls give me some exampls or some articles website address.

thanx
G.Prabhakaran
 
C

Champika Nirosh

This eaxmple illustrate what Peter is saying

try
{
System.IO.FileInfo Info = new System.IO.FileInfo(tstrFileName);//This
may throw a exeption since file might not be exist
}
catch ()
{
}

string a = "hello";
string b = "How are you";
MessageBox.Show(a + ", " + b); //Even a file not found exception occured,
this line still be executed

Nirosh.
 
G

Gopal Prabhakaran

Dear Champika Nirosh

try
{
line 1: --------------------------//Assume that This may throw a
exeption
line 2 : ------------------------
line 3 : -----------------------//Assume that This may throw a exeption
line 4 : ------------------------
}
catch ()
{
}

Is there any possiable that when line 1 and line 3 throws exeption , it
must excute the line 2 and line 4.
and finally i want to write the exeption message in log file

thanx
prabhakaran.g
 
C

Champika Nirosh

string lstrError;
try
{
line 1: --------------------------//Assume that This may throw a
}
catch (System.Exception e1)
{
lstrError = e1.Message;
}
line 2 : ------------------------
try
{
line 3 : -----------------------//Assume that This may throw a exeption
}
catch (System.Exception e2)
{
lstrError += "\n" + e2.Message;
}
line 4 : ------------------------

That's All

Nirosh
 
C

Champika Nirosh

Same time Please note that this is possible only if the line 2 and 4 has no
effect at all from the exceptions occured at line 1 and 3. but if they have
any effect then you may have to handle the exception accoringly

regards
Nirosh
 
G

Gopal Prabhakaran

Dear Champika Nirosh

Is there any other way ? say i have 100 lines what should i do ? i don't
know which line will throw error ?

Pls tell me other way ?

Thanx
G.Prabhkaran
 
C

Champika Nirosh

I think you got to know about the code you are writing so there you should
know which line throw a exception, again your requirement also quite
awkward.



I am not sure how you are executing a line while ignoring the exception
thrown by the previous line I mean these line should have some relation.. I
guess this has something to do with the initial design of the system.



Please get me more specific data then I can try to help you.



If you have already given the full detail the solution is cathing all the
exception thrown by each line (even though there are 100 lines). I mean not
all lines throw exception so you got to find which line throw exceptions ..
lines like string s = "hello"; will not throw a exception at any rate.



Nirosh
 
G

Gopal Prabhakaran

Dear Champika Nirosh

When I try to add a record in a table (' using funtion zAddRec which shown
below'), Say if some other user has locked the table . I have to wait for
some time ,and i want to add the record after he releases the lock

how to proceed with managed exception.

Example :

Private Function zAddRec(sod As tsod) As Boolean
zAddRec = False
On Error GoTo err1
open_table
If Not RsAddNew(mytbl) Then Exit Function
mytbl!Fiscalyear = sod.Fiscalyear
mytbl!CusAcNo = NTrim(sod.CusAcNo)
mytbl!SoNo = NTrim(sod.SoNo)
mytbl!Slno = NTrim(sod.Slno)
If Not RsUpdate(mytbl) Then Exit Function
close_table
zAddRec = True
Exit Function
err1:
gERC = ErrDetails(" B1SOD AddRec")
Select Case gERC
Case gResume: Resume
Case gResumeNext: Resume Next
Case gEnd: End
Case gCxlUpdate: 'IF APPL write code here
Case gUptoU: 'Code here Context sensitive
Case gExit: 'Do nothing (Drops down)
End Select
Exit Function
End Function

****************************************************************************
*****

Public Function ErrDetails%(ByVal Prochead$)
Dim fno%
Dim Ans As Long
'
ErrDetails = gExit
'
If Err.Number > 0 Then
If Err.Number > 3000 And Err.Number < 3999 Then

Select Case Err.Number
Case 3020 'using update without edit/addnew
ErrBox Err.Number & " " & Err.Description
ErrDetails = gEnd
Case 3197
Ans = MsgBox("Data has been changed by another
user,Overwrite changes ?", vbYesNo)
If Ans = vbYes Then
ErrDetails = gResume
Else
ErrDetails = gCxlUpdate
End If
Case Else
ErrBox Err.Number & " : " & Err.Description
ErrDetails = gExit
End Select
Else
ErrBox Err.Number & " : " & Err.Description
ErrDetails = gUptoU
End If
fno = FreeFile
Open oSession.Path & "Err.Txt" For Append As #fno
Print #fno, ERROR DETAILS
Close #fno
End If
End Function

Thanx

Gopal Prabhakaran
 
C

Carsten Posingies

Gopal said:
Dear Champika Nirosh

When I try to add a record in a table (' using funtion zAddRec which
shown below'), Say if some other user has locked the table . I have
to wait for some time ,and i want to add the record after he
releases the lock

how to proceed with managed exception.

Example :

(snip)

10 Was your example just a generic example?
20 If not:
30 Are you sure you've understood how the .NET framework handles
database I/O?
40 If not: Read the MSDN, GoTo 30
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top