|
-
Sep 26th, 2011, 07:56 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Best to way to trap NullException
Hello. Anybody can suggest whats the best way to trap the null exeption from this code of mine.
vb Code:
long last_Sent; long last_Rec; private void timerPackets_Tick(object sender, EventArgs e) { try { string strSent = null; string strReceived = null; long strStatdon; long strStatup; long curr_Sent = 0; long curr_Rec = 0; long speedDown = 0; long speedUp = 0; strSent = clsMethods.strLines(5); strReceived = clsMethods.strLines(4); string[] arrSent = strSent.Split(','); string[] arrRec = strReceived.Split(','); curr_Sent = long.Parse(arrSent[1]); curr_Rec = long.Parse(arrRec[1]); speedDown = curr_Rec - last_Rec; speedUp = curr_Sent - last_Sent; strStatdon = speedDown * 8; strStatup = speedUp * 8; StatusDown.Text = clsMethods.convertSize(strStatdon) + " /s"; StatusUP.Text = clsMethods.convertSize(strStatup) + " /s"; lblUP.Text = clsMethods.convertSize(last_Sent); lblDown.Text = clsMethods.convertSize(last_Rec); last_Rec = long.Parse(arrRec[1]); last_Sent = long.Parse(arrSent[1]); } catch (Exception ex) { MessageBox.Show(ex.ToString(),"Information"); }
For I just popup the error being generated.
On my code sometimes this two line
strSent = clsMethods.strLines(5);
strReceived = clsMethods.strLines(4);
doesn't return a value.
that's why this line
string[] arrSent = strSent.Split(',');
string[] arrRec = strReceived.Split(',');
throw me an exeption.
I want when nullreference error occured just to continue the timer tick until that two line have value in it..
THanks.
br.
VB 6.0 = "Self-Study" Then
vb.NET = "Self-Study" Then
C# = 'on going study.....
-
Sep 26th, 2011, 08:06 AM
#2
Re: Best to way to trap NullException
be proactive not reactive... check for the null values first... if the string isn't null, then continue with your code... if it is null, then skip it...
-tg
-
Sep 26th, 2011, 08:07 AM
#3
Re: Best to way to trap NullException
It is advised to check the array length before getting the value from the array. If you still need to pass the null reference exception then go like this
vb Code:
try { } catch (NullReferenceException ne) { //Log the error and continue } catch (Exception ex) { MessageBox.Show(ex.Message); }
Please mark you thread resolved using the Thread Tools as shown
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|