D
Dave Mihalik
Can some show me how to implement this java program using Ruby?
I am simply trying to prevent the testclass from being instantiated in
the constructor.
I am then checking to see if the the class has instanatiated properly.
class testclass
{
public testclass() throws Exception
{
Exception testexception;
testexception = new Exception("Instantiation cancelled.");
throw testexception;
}}
public class testprogram
{
public static void main(final String taArgv[])
{
testclass mytest = null;
try
{
mytest = new testclass();
}
catch(Exception myexception)
{
System.out.println(myexception.getMessage());
}
if (mytest == null)
{
System.exit(1);
}
System.out.println("Instantiation not cancelled.");
}}
I am new to Ruby but this is what I have so far:
class Testclass
def initialize()
raise "Instantiation cancelled."
end
end
begin
mytest = Testclass.new()
rescue Exception => e
begin
puts e
exit 1
end
puts "Instantiation not cancelled."
end
If the raise line in the initialize method is disabled, the puts
"Instantiation not cancelled." line does not execute.
I am simply trying to prevent the testclass from being instantiated in
the constructor.
I am then checking to see if the the class has instanatiated properly.
class testclass
{
public testclass() throws Exception
{
Exception testexception;
testexception = new Exception("Instantiation cancelled.");
throw testexception;
}}
public class testprogram
{
public static void main(final String taArgv[])
{
testclass mytest = null;
try
{
mytest = new testclass();
}
catch(Exception myexception)
{
System.out.println(myexception.getMessage());
}
if (mytest == null)
{
System.exit(1);
}
System.out.println("Instantiation not cancelled.");
}}
I am new to Ruby but this is what I have so far:
class Testclass
def initialize()
raise "Instantiation cancelled."
end
end
begin
mytest = Testclass.new()
rescue Exception => e
begin
puts e
exit 1
end
puts "Instantiation not cancelled."
end
If the raise line in the initialize method is disabled, the puts
"Instantiation not cancelled." line does not execute.