try catch in C#
-
How can i get : the value or Parameter that cause error in try block? Simple example : try { int i=0; int j=2; int k=j/i; } catch(Exception e) { messagebox.show(e.Message); } now i wanna to have these :
in line 5 the exception occurred and i=0 made the exception;
-
How can i get : the value or Parameter that cause error in try block? Simple example : try { int i=0; int j=2; int k=j/i; } catch(Exception e) { messagebox.show(e.Message); } now i wanna to have these :
in line 5 the exception occurred and i=0 made the exception;
you mean ,
try
{
int i=0;
int j=2;
if(i==0)
{
throw new ArgumentNullException();// or your exception class
}
int k=j/i;
}
catch(Exception e)
{
messagebox.show(e.Message);
}We are haven't bug,just temporarily undecided problems.
-
How can i get : the value or Parameter that cause error in try block? Simple example : try { int i=0; int j=2; int k=j/i; } catch(Exception e) { messagebox.show(e.Message); } now i wanna to have these :
in line 5 the exception occurred and i=0 made the exception;
jojoba2011 wrote:
the value or Parameter that cause error in try block?
If you're asking what I think you are, you can't get that detailed of a message.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
How can i get : the value or Parameter that cause error in try block? Simple example : try { int i=0; int j=2; int k=j/i; } catch(Exception e) { messagebox.show(e.Message); } now i wanna to have these :
in line 5 the exception occurred and i=0 made the exception;
I exactly want this message :
line 5 exception occured
i=0 made this error -
I exactly want this message :
line 5 exception occured
i=0 made this errorStack trace will have these details. You have to parse the stack trace and extract this information.
Best wishes, Navaneeth
-
I exactly want this message :
line 5 exception occured
i=0 made this errorMove
i
outside the try/catch block so it is visible in all sections, something like:int i;
try
{
i=0;
int j=2;
int k=j/i;
}
catch(Exception e)
{
string msg = "i = " + i + " " + e.Message;
messagebox.show(msg);
}txtspeak is the realm of 9 year old children, not developers. Christian Graus
-
How can i get : the value or Parameter that cause error in try block? Simple example : try { int i=0; int j=2; int k=j/i; } catch(Exception e) { messagebox.show(e.Message); } now i wanna to have these :
in line 5 the exception occurred and i=0 made the exception;
i=0
didn't cause the Exception; it'sj/i
. You could put the three statements each in its own try/catch. You could keep track of where you were in the process:int x;
try
{
x=0;
int i=0;x=1;
int j=2;x=2;
int k=j/i;x=3;
}
catch(Exception e)
{
string err="";switch(x)
{
case 0: err = " caused by i=0" ; break ;
case 1: err = " caused by j=2" ; break ;
case 2: err = " caused by k=j/i" ; break ;
}messagebox.show(e.Message + err );
} -
How can i get : the value or Parameter that cause error in try block? Simple example : try { int i=0; int j=2; int k=j/i; } catch(Exception e) { messagebox.show(e.Message); } now i wanna to have these :
in line 5 the exception occurred and i=0 made the exception;