Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Exception handling2
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 // How are you saying that the program that you have written is achieving ur intentions? //what is the intention of ur program? what do u want to achieve? using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class ExceptionHandling { public int[] x= new int[5]; public int[] y= new int[5]; int id; public string str; public ExceptionHandling() { id=0; str=""; } public ExceptionHandling(int[] tmp,int[] tmp2,int t, string s) { try { str=s; id=t; for(int i=0;i<tmp.Length-1;i++) { x[i]=tmp[i]/tmp2[i]; y[i]=tmp2[i]*tmp[i]; } } catch(IndexOutOfRangeException e1) { Console.WriteLine(e1.Message); } catch(DivideByZeroException e2) { Console.WriteLine(e2.Message); } catch(Exception ex) { // Exception ex=new Myexception(Exception e3); throw new MyException(ex); } } public int ID { get { return id; } set { id=value; } } public void AddInfo(int[] tmp, string s) { try { str=s; for(int i=0;i<tmp.Length-1;i++) { x[i]=tmp[i]; } } catch(Exception e1) { Console.WriteLine(e1.Message); throw new MyException(e1); } /*catch(Exception ex) { // Exception ex=new Myexception(Exception e3); //throw new MyException(ex); }*/ } public void Display() { Console.WriteLine("String Value=: {0}, Int Value=: {1}",str,id); Console.WriteLine("Array Values:"); for(int i=0;i<x.Length-1;i++) { Console.WriteLine(" "+x[i]); } } }//End of ExceptionHandling Class public class MyException:Exception { public string str; public MyException():base(){} public MyException(string msg):base(msg){} public MyException(Exception ex) { str=ex.Message; this.AccessException2(); } public static void AccessException(Exception e) { Console.WriteLine("Properties Changed: "+e.Message); } public void AccessException2() { Console.WriteLine("Access not available :"+str); } } public class Program { public static void Main(string[] args) { int[]ar = new int[]{1,2,3,4,5}; int[]ar2 = new int[]{3,4,0,6,0,8,9}; int id=100; string strval="shashank"; try { ExceptionHandling Eh=new ExceptionHandling(); Eh.AddInfo(ar2,strval); // ExceptionHandling.ID=150; Eh.ID=200; ExceptionHandling Eh2=new ExceptionHandling(ar,ar2,500,"Hegde"); try { if(Eh.ID>id/0);//{throw new Exception();} only system exceptions } catch(Exception el) { Console.WriteLine(el.Message); } } catch(Exception en) { Console.WriteLine(en.Message); Console.WriteLine("Outer Catch"); throw new Exception(); //MyException exp=new MyException(); MyException.AccessException(en); // MyException.AccessException2(); } } } }
run
|
edit
|
history
|
help
0
zicaC#
sdfrgthyjujyhtgtg
biswa
Lab7
Joro Football Player
deletevowels
PayU Lu c#
eze
bc160400236
Decrypt Encrypt