All your videos... "key-word" searchable, readable and printable!
And it's 100% FREE  (nice!)
Newest transcriptions for...
Search kudvenkat Database for "Spoken Words":
"2012-06-30 16:01:50"
Part 42 C# Tutorial Custom Exceptions in C#
\\hello welcome to begin technologies I'm think that this is not what to do custom exceptions in this section we learned went to create custom exceptions creating a custom exception from the scratch throwing and catching the custom exception that you create now to understand customer exceptions prop late you should already have a good understanding of inheritance exception handling basics and and exceptions if you want to learn more about these concepts up peace watch pots 214040 all this week series not when do you usually go for creating your own custom exceptions why is there a need to do so because if you look provides us with many exceptions we have high locks are exception you know index hold a trade provides us with many exceptions what is the need for us to create a except that's what you lot so in a bit but to find out all the exceptions that are already available what what do as you debug menu I checked exceptions but this window will show you all the available I don't duck and exceptions already and to get to this one to another cable truck at this alt control eat what example you know going on that are if you are trying to meet I'll add of the pilots on surely so if I exceptions we fight one to find that I did not no exception go to common language runtime exceptions and we know that any classes to do what system I or are present and now I'm just I will namespace so if you see here system but I would not file not found exception okay so similarly there are some exceptions framework now did made me scenarios rare one obvious exceptions that already available it may not be at the right and I have to describe the problem that I have let's look at an example now but to have an web application either quadrant of this application such that it should only allow us log at one time and it does the right now if I am already logged in and then rose of and if I take to open another browser window and if I take a game log in there it should do and as it was it's saying you out or did that and to serve this purpose and to describe this problematic neatly and now we don't have any exception that's hardly available with the Trent web this could be one of the classical example us when you want to design your own custom section okay and to do that we have certain steps and it's really easy to do that okay so let's look at step by step of creating a little exception okay so to create a custom exception and we know that an exception is nothing but a clock for example if you look at the exception class that's out it's a class by itself okay and we know that all exceptions within framework directly on it directly and had it from this I'm not exception class system but exception classes the basic plot all of the exceptions that are already available but then and what now if you want to create your own custom exception class and if you want all the features that an exception object up having then you make your custom exception clause inherit from that base exception cloth does me you don't have to write any of that ID you and had all the functionality basic exception plus that's why when you creating your own exception class the first step in doing so east created plots that and headed from the exception class so public class and the one to name a car class as user already log 10 and you want to make this class and headed prom the exception base class okay now you know that you know we we know that we have file not found exception for example look at that and find out won't accept by the rates namespace we have to or that sort I AO and now if I try to look at the file not found exception for example file not found exception if you look at this file not found exception all our you know index total stranger exception all the exceptions basically and with the suffix exception okay so what's the advantage of that basically just by looking at the name of the plot you can say okay this is an exception clock okay so even even exceptions you know if I see use at Albany log Dan okay is this a regular class at an exception class so just to identify to differentiate that we can you know it's it's it's a common convention to actually and your class name let the exception suffix this way by looking at the name of the class you can say okay this is an exception class just like filing on exception are no index hold of except she are invalid operational exception use it already locked an exception okay so follow that comment that even if you don't do that and amid this exception don't get any compile time errors but you're slightly deviating from the design guidelines creating a custom except class right so I mean to create your custom class at the minimum that is what you have to do your doc creating a custom except class okay now let's have example if you want to to a file not found exception how do you do that you use the tool kit would throw no file not found exception okay similarly now let's go on and on this fast when you get on this what happens you know we'll get that system but I would not I won't exception okay similarly if you want to call your own exception what do you do you say user on teddy log then exception and then beyond that you get that exception okay but the defense says if you look at the file not found exception if I want to customize the message that we should I am user I can do that by using the construct okay I can possum and message to this pilot section and let the for example file X. Y. said is not farm when you do the S. what happens this message will be shown as part of that exception objects so file X. Y. Z. is what are now is it possible to do that kind of customization well my exception class because why you construct a does not I mean you are exception cost does not have any constructor you didn't provide any constructor if you don't write a concept of being with that doctor trying time and what went on lift weights a default Adam let's construct and that's the only one which is available now if you have to provide your class the the flexibility of possum gonna mess it's with the devil okay customize them at it passed cost your custom exception then you have to call it that comes and we do that it's pretty simple let's the S. alright so public use it all the dialogue then and to this I possum the strength that I meet are let's call that my state not if you look at the exception class we know that the exception clause also high doesn't if you look at this now I work colossal use it all day long been exception custom exception classes actually in had a big problem the exception based class okay so if you look at the exception based class you right click on that and say look the definition look at the exception based class it has a construct which takes us trained Iraqi to so now all you have to do list book the base class struck by using the bass key word and then it will be this or loaded lotion passing again the message so now what are we doing you're communicating come the derived class to the base class okay using the bass keyword okay so now if you look at this one we get it leads greedy he up because once you no way to construct a puke lost the default that I'm less caught up construct up provided by doctor trend what is taken away so if you want also want users to be able to clean it up just without putting any message that should be able to create you log that exception if you want to read that capability than probably have another construct which doesn't take any parent meter now here we don't want so what we had essentially doing killer is constructed when reading again we have covered that in a separate session please check on and all that specific product comes ... overloading okay now if you look at this construct that you didn't take any parent and the exception based gloss we already have a constructive which does not take any Parramatta I'm your derived class just and will that specific struck dumb you were loaded base class constructors okay now what have you done until now you have provided to constructors to your class okay one which does not take that I'm into one which takes I mean I'm the user wants to customize the message all they can do as okay user is logged Ben no duplicate sessions allowed you know you can basically customize that the VA you want okay so now if we run this you should see that custom message alright now Bach 21 yes you have learned about in that exceptions what is the advantage of using in that exceptions in exceptions basically allow us to track the origin of exception okay so if you're not sure about and exceptions I would strongly encourage you watch this part 21 it will continue with this section so we know that in that exceptions basically allows us to track the origin an exception now if you look at your clock it's not possible you know for this exception track the orginal exception okay so if you want to provide that capability for you are custom exception class then you need provide that would look at Goshen okay off constructor if you look at the base lost it has gotten not the construct a look at this construct it takes in and meditate ask will last another but I'm type exception okay and basically this is the original exception any impostor that's apparently okay so let's go and why that construct arrest lots of public use it already logged an exception the fast but I mean that is of type strain and that next but I mean delays of type exception and this one is going to be in that exception and what you do here are you call the base class constructor passing again the message and in that exception we have already seen that best bass exception clause have that construct so call back overloaded motion of the base class constructor Pasanen that aspect to panic meters so now we have provided another constructed S. Watson now using your closets simple to track and accept okay so if I try to go out and create a an instance of this class we could that there are 3 or what what did bush now I see that in the intelligentsia alright now another important thing it might not this glossed it works but it only works within the same application but Watson application domain women talk about application of names let me talk about him okay web services have WCS okay basically lay in there replications that they want off tele active example how application anyone into picking 8 to now if I want application 81 application 8 to then the objects that you create with an application anyone Hastert cross that brown boundary of this a one application and reach application 8 to boundary now when you have to woo objects across applications palm trees does objects need to be he realizable okay so we'll talk the concepts of civilization civilization it's nothing would break down that object packets that can be transmitted over the network so if you want to move your object from one application domain to another application domain over the network then the class has to be serializable okay so if you want cut custom exception class to be remote to build our CD Eliza better then the first thing that you have to do is to decorate this class with serializable attribute and then if you look at the base exception lost the biggest exception class had and ... looted construct what's he like nation but lets us which takes since he realization and call and if you look at the intellisense the civilization and for loss is actually present in system got them on time.CD allies nation and space okay so if we have to use that object we have to import that name space and then it will go this construct our from about plus so let's provide that so last of all let's go ahead and important system doctor on time.serialization yes and then we need to provide a construct our for all the plots which supports legalization we use it all in a lock that so if you look at the base class what is the last but I'm into it have to be civilization them for I the next but I'm to the easel types to streaming hardback so civilization than for let's call that S. our info and the other one is streaming context let's call the object reference variable as context and that's what you need to do we need to call the base class base exception class constructor passing again that I'm just in full and streaming context alright so I got lost at this point I would exception class is almost eaten bent to any of the exception up plot that's available with train what you have provided all the constructor older did construct and instructor where shins it's the end user can use for right different purposes and obviously so if you want to call any of these constructors that's possible and if you want to handle this exception through it it through it and the tribe LaChiusa 2 key word and to catch that news in user alter the logged an exception E. X. and comes World Trade line E. X.. sage and if you pass any in the exception are you know when you're doing this track that an exception look at this if I say karma you can actually see one of the ... alerted constructors and I taking an extra parameter and the other parent is type in an exception okay okay so when viewed on this now she only be method of that exception did okay so let's quickly review what we have seen so far so creating custom exceptions what are the steps create a clock that derive from system good exception cloth and of the Carmen naming convention and the class name exceptions suffix it looks all drop that exception exceptions and with the exception suffix and if you want you up exception class to come standards then name your class so and we provide a public constructor that takes on a street that I mean does this construct us simply passed the strength that I mean base exception class at what does this right last April Wade into the flexibility for the costs and the message that they want your exception class and if you want to track in the exceptions you basically have to wide out you know that 100 bush the construct a I simply at Lee if you want you are exceptions lost be working at cross application domains then you need to lock your class that serializable and remember that it is also possible right you're wrong customs you know I think if you look at this example yeah using the deep us here like this that's provided by the basic steps clocks by it will end up by providing that instructor which that base plus he led Asian up but on the other hand it is what possible to provide your own customs he led nation so we'll be talking about you know like they should and customizing you know I think in the later session in detail that's it for today thank you for listening have a great day //
"2012-06-28 21:22:55"
Part 41 C# Tutorial Inner Exceptions in C#
\\welcome to present to Congress I am like it this is what you want in exceptions in this thing they've learned the basics of an exception I would watch what P. exception handling we have seen that are you know an exception that's nothing but actually an instant cloth that it's being gone when I'm not who seem even dockers and handle exceptions we use try catch and finally blocks and we know that and any exception object with a drop that actually derives directly or indirectly from order exception lost I mean on the base exception plots expose would you like messy stack trees in an exception except for in the previous session we have seen what the message and stacked stack trace probably gives us in this section we will learn about in an exception okay up this a little bit tricky one so let's understand in exceptions an example what I want to do is I want to create a very simple program that can add up my dad that can do white so the program will probably use the trend of the last number added and the second number and once you have with the numbers will take you divide that I would meet I do that there are several exceptions that can occur so let's stop the programs must lock the user grand other fashionable etrade line and tell this number so once the user enters the fuss number we have to read it from the council read it from the comms will be used guns will duck feed line and you know that console.she'd line it does that not but in the form of a string so we need to cut wood that any teacher use the time work plus 2 intended to come redacting teacher once we have converted that to India student inevitable for calculation but sure Slater so I am storing it in a variable called fussed number similarly prompt the user to enter second number and lead that from the console come with that team to ya adds to now available because I cannot and finally Catlett that is that result is equal to last night while my second and what we want to do we want to and that back to the zmodo trade line result yeah wells so reprint that is left now if you go ahead and run this program I realize the use it and fast not well he endorses fussed number one second mullah as it is to press any key to company not this program can fade for him at 18 reasons enough for example if it on this program if I enter alphabets instead of numbers things like that obviously there is a format exception because datastream and would it be media similarly this program can also fail if Landore if any big number you know obviously an integer variable can hold on the A. M. number of specific sites but this is a large number and India Brady bill can not or that or wish you all and will get an a worse way exception and since we are dividing 2 numbers if you divide that number by 0 there isn't a central IT and obviously it's illegal and mathematics so that's why we take to divide and number by 0 what happens we get a divide by exception so this program fails what about 8 okay no metaphor which reason this program has in it when it fails there is an exception so I want to be able to handle that exception and to do that me use try catch blocks try catch whatever it is the exception that occurs I want to catch that not only catch that exception just give a message to the they're saying that you know there is a problem try later okay not often I catch the exception what should read beat we should either be logging that exception auto emailing the exception and when I Graham and all of that okay up but in our case let's go ahead and log that while I have actually created a file ya I have a seat cullin sample files directory and then those directly I have a log file log.T. XP and if you look at that it's currently empty I'm there is an exception I want right that exception of left law class and to do that I would make gene writer class and screen writer plots is present insist I your name space to read the input and output I was I but so let's use stream writer class screenwriter SW is equal to new stream right and if you look at the construct of the stream right the class there are several web logs available but you use this second awarding ordered version which takes St as part of the file so watched apocryphal file it's actually present string let's call this has filed park the baby bell and it's the pot it a sequel shambles fires long duck DXT she colon backslash sample size backslash log dark DXT and since backslash there has got a specific meaning you need to use right about ritual okay not be possum the file pot 80 ago do the screen writer clocks and then what do you need to do is okay the stream writer plus we'll be in a right to that 5 okay not you need to tell you the stream right that what you want right I want to write the exception type let's example it's automatic section I want yes tried that the file if it's a divide by 0 whatever it is the exception tight I want right type them in 2 that log file add to get the type of the exception you actually have a method called get tight and we know that if we want to the mess 8 we can use the message property the US tracks stack treats we can use the stack trace property similarly find one to find the type of the exception is a divide by 0 automatic section overthrow argument what is the pipe with the exception then you can you yeah right method I am on that you can actually use that name property are you can also use the full name which we love so game if we meet qualified name including the man's fist let let's say we want I want right that type in some and the tight named to the file so right that and then finally does this do you stream writer okay so far so good I'm that is an error S. W.'s available but please use lie stream great idea screenwriter.that is a method called right we use that right now so we were using the object like a but you know a a method but that's an object alright so now if we go ahead and drop that's what's gonna happen if there is an exception they exception and we'll get it done let's let's let's see that's actually that's okay I'm and up and up fussed number let's say and they're a very big not well obviously an idiot looking out or that that would be an exception so when there is an exception what happens the catch block catches that exception right the exception typing for me this file and then it seemed I think there is a problem try later now if we go towards older you should see overthrow exception and if you want to ride the stack trace and other information that that's out on all you need to do is just say as W..try whatever you want right for example sage and similarly you can also do the same thing stack trace tomorrow if item this and that maybe I enter some also that's obviously that it will fail and become yeah chak format exception input string was not in the correct format and obviously there is no space because we need to tell that you know probably can just say yes W. tried line just a form of that a little just write a line in that fight the numbers game and some of the beds it fails again you go check that so now it comes namely let's hope it will be a hit to lead to learn about in exceptions okay all is well now you know there is an exception the filings that it rights to that what what if this file is on there and the file is not there we will get a fly locks on exception okay so fast I mean no just to be safe we will check in the file exists on part of the file exists only then I want to write that file otherwise I won this round through a file box or exception so how do we do that I didn't system that I hope lost that is it I looked lost and on this file flat Daddy's a static method exists and to this method you can actually possum the final pot and it will ratify the filings that it looked true if not lit up tossed save the file at this spot excess only then do this the file is not there then jul and new while not found exception so we have throwing okay another exception yeah and you you can give them meaning to message you want may be and just say this file pa if you look at that the construct a file not found exception and all that is a message there is one overloaded version which takes the message so the message I want to say it's okay if I let this pot at this rate it will have that pot it's not pleasant I just want sure that message I mean throw an exception with that message now if you look at the other wooden or did bush and it's talking about an exception okay now what is the speedometer does not think by I can look at this cluster for why did we ever get to do this cash box because there is an exception in a well trained to execute this court as a result of that exception we got into this block and we have lighting that exception on the old you know exception would be almost like section okay so when that exception occurred meet you know the control came to the catch block you're trying to write the exception and this file but unfortunately we don't have that file there and we're going another I mean obviously if the pilots more that we can apply to it so we have to have silence or exception but I don't want to lose the orginal exception which landed me in this catch okay so if you want retained that exception that's why are you passed that exception yes in this case as Pat I meet our to the constructor of this exception so what will happen this is the you know this is the original exception and this is our current exception okay so now let's fund this program and see what happens you could this an exception is being thrown from the Catholic and by the way who threw an exception it would be have not seen about this in the previous session and dance would be a couple of this yet so if you want to intentionally through an exception you use what okay so yet throwing another exception and since we want to retain the orginal exception which landed us in this catch block yeah I think that exception that's it pattern into the constructive current exception alright now let's run this program and see what's going to happen and I had on this okay and they are fast number I'm gonna enter then enter your second number 0 so obviously gonna get a divide by 0 exception which will take us to this catch block and then what happens it will okay the pilot still there so it will not rule silence one exception but anyhow let's see that so obviously what happened here it can heal the file is there so the divide by 0 exception will be looked at that lock I've so I believe come here and open that divide by 0 exception attempt do I buy 0 alright so how do I eat I'd make this program fell so that we get because that's what so now let's say I will mark this this log one B. are can just change somebody but somebody has to let's say the name of fire log one know what happens when you program traced to write the exception and that long 5 it will not find that file and there will be another exception yeah okay so let's not sexually so I am the first number 10 and the second number 0 and what happens you could this now what happened try to divide the number by 0 so obviously divide by 0 exception Molucca it comes to the catch block and it tries to you know find this file its smartphone so it comes to the as block it doesn't even existed this line and this cryptic message and you so end users will not understand anything about this exception it's definitely cryptic so what we want to do if you want to handle this exception then you want to wrap this entire chord in another tire try block so what I want to do is put another try block try less try that and there's another catch block catch exception let's say we already used E. X. here so we have to use I guess that's obvious exception okay now let's go ahead and put a break point here and another program in the debug more let's go to another break point in this case what now we run the program it's asking the use of data fussed number 10 second number 0 you can list the moment we do that be kept a divide by 0 exception attempted to divide by 0 and if you get this divide by 0 exception okay now what does this Catholic place to do it tries to write that exception that's 5 so let's see what happens okay that particular file I would checks okay does this file exists she simplifies do we have the log file now it's log one .DXT the pilots mob there so what happens it comes to the S. block and what is that long going it is throwing another exception file narcotics section okay obviously because that file not found and then to this construct of the a plus in the orginal exception as well so what happens this object will be torn along with this wrapped inside the in that exception property of that object now what happens this entire war is in the outdoor trade bloc this catch block a press that stand here are you can actually see you know could this in that exception is there something in the in the exception and if I expand that divide by 0 the oriental exception is divided by 0 exception what what is the current exception while not all exception okay you have to get another exception now let's stop this okay let's print those messages in the exception and the current exception sold outright lie safe I want to get the current exception what we will do section this is the exception object .get type let's say just one the name of the exceptions would that solve current exception and just to make a differentiation you know say could land exception that's a kind of exception and similarly if we won the in the exception we will need to say this exception object obviously the 6 exception object along with the method and Swiss property there is an exception OPS well so in an exception Dr you know maybe get tight and then the name that so we know that in this case in an exception is divide by 0 exception and stop there okay so let's run this now okay into fussed number 10 and a second number 0 it tries to ride that I own some reason the exception no information oh okay that's because would that placeholder okay so let's on that now and the first number 10 and a second number so in that exception is I mean current exception is phylon found in exception is divided by 0 okay now let's say what happens if you don't pass this exception object as a parent we did to this concept but let's see what happens I've you don't pass the old you know the the only thing that exception object then that in that exception brokered deal this exception object will be now and if you try to invoke any method of property I and now the object you will get out exception that is why you should always be checking if an exception let let me show you that so I've done this now I understand I and other Julie let's put that in the but what and actually see that so let's run this and the first number 10 and a second numbers 0 so we get a divide by 0 exception I press F. Dan if I listen are there we get violent exception and we come here and without a catch block look at him we're not passing the orginal exceptions so in that exception on this subject has been nada if you look at them that exception it's actually now okay and now it as this is not a look at the intellisense as this object is now I'm trying to you know get type method on I'll object beget and now the reference exception so let's see that okay prince the first line actually if you look at the console and we got the current exception but you know that in that exception is now if I am well my personal would lead them to listen shows that I'm on the model object recalling get tight it will fail here and that is normal and this cast look is not in any trade block so the program will crash oppressive 5 you can last object reference we get and not a lot of evidence exception object reference set to an instance an object okay so that's why any time you try to live to see the in an exception make sure you always check F. that exception that it exception naughty or tomorrow only then this way we can avoid the mother that's exception if we get on this now and if that's what Dan number 0 so it will only Pentacon exception and the exception is our that okay but if you on the Democrats and what you can do you can just possum Belgian exception object to best constructor and it will give you will do you no exception and younger exception sold exception pilot plant in exception do right by seal I hope you have enjoyed this session so what is the in the exception property das it returns the exception and so cost the current exceptions so they that exception will actually give you or you have exception cost the current exception but for that to happen you need to pause the orginal exception as a parent meet up the construct up off the current exception check to retain the original exception possibly as a parent about always check if an exception is now before accessing any property or method on the in the exception object otherwise you will get in I'll reference exception I do get the type of man that exception we just you okay tight method and remember the bass exception class has all these properties as each stack trace in that exception get type which have really valuable find letting it slip from we're debunking all right on this slide you can find this was what if we looked at things happen to me questions that's it for today thank you for listening have a great day //

Example Scenarios ("Expectations"): * +60% is "sufficient" for search engines to find your content, and route users directly to your auto-deep-linked videos.