Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 3 questions...
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Homer_simpson




PostPosted: Tue Feb 24, 2004 6:59 pm   Post subject: 3 questions...

i know these questions will sound noobish... but hey i'm a noobie at this...
questions:
what does "super" do?
what does "try" do and how to use it same with "cache"...

Response will be appreciated =)
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Tue Feb 24, 2004 7:36 pm   Post subject: (No subject)

super

Much like in Objective-C, "super" refers to the same object as "this" ("self" in Obj-C). However, the "super" keyword says "look in the super class for the method". This is useful when you've inherited a class and overridden one of its methods, but you then want access to that original method occassionally.

try / catch

"try" literally "tries" a block of code to see if it works. If it doesn't, and something "throws" an exception as a result, then you can "catch" and handle the exception.

code:
try
{
   doSomething();
}
catch (Exception e)
{
   doSomethingWithTheException();
}
BlAcK TuRtLe




PostPosted: Sun Feb 29, 2004 5:36 pm   Post subject: (No subject)

Using try and catch, you can make it so that if a user enters a double for and int variable, the program won't bomb out. Can't remember the exact coding tho.
rizzix




PostPosted: Mon Mar 01, 2004 3:59 pm   Post subject: (No subject)

basically error handling in Java is done using the try-catch-finally mechanism.

a method is declared to throw an exception if there is a potential error that could arise with the given data in a perticular situation. for example if u had a method that divided one of its args with the other, it is possible that the second arg is zero.. which can result in an error. Now instead of handling this situation itself (like we are forced to do in turing) we can get the client code (code that "calls the method") to handle it. We do this by signaling that a DivByZero error has taken place. and so in that method we will write some code that will check to see if the second arg is zero, if it is it throws an exception.

now since the client code calls that method that is declared to throw such an exception it is necessary for the client code to catch that exception if it is ever thrown.

to do this we enclose the call to that method that generates the exception in a try block and write a catch bock right after that try-block to catch that exception.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: