🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java.programmer
Article #629

Re: Why, oh, why??

#629
From: malissa
Date: Tue, 10 Oct 2000 00:00
62 lines
2130 bytes
It prints Exception because the variable "e" in your catch is of type
"Exception".  If you change your variable's type to "RuntimeException",
you'll see the behavior you were expecting.

When passing variables as method parameters, the variable's type is what
determines which overloaded method is called.

Malissa

>
> Why does this not work?? When printing the StackTrace it prints an
> Exception, and not a RuntimeException as I hoped?
>
> (This is a test setup, proberly not making any sense)
>
> --- File : MethodOverload.java
>
> public class MethodOverload
> {
>     public static void main(String[] args)
>     {
>         try
>         {
>             throw new RuntimeException("e");
>         }
>         catch (Exception e)
>         {
>             try
>             {
>                 throw TestObject.method(e);
>             }
>             catch (Exception e1)
>             {
>                 e1.printStackTrace();
>             }
>         }
>     }
> }
>
> --- File : TestObject.java
>
> public class TestObject
> {
>     public static Exception method(Exception test)
>     {
>         return new Exception("1");
>     }
>
>     public static Exception method(RuntimeException test)
>     {
>         return new RuntimeException("Test");
>     }
> }
>
> Regards,
>
> Frederik Hansen
>


Sent via Deja.com http://www.deja.com/
Before you buy.
Technical Details
Message-ID: <8rvsh8$m0g$1@nnrp1.deja.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <39E35A22.2748A7F6@roirex.dk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f9a23,58c4f0a3e7100464
X-Google-Attributes: gidf9a23,public
X-Google-Thread: 10a146,58c4f0a3e7100464
X-Google-Attributes: gid10a146,public
From: malissa@my-deja.com
Subject: Re: Why, oh, why??
Date: 2000/10/10
Message-ID: <8rvsh8$m0g$1@nnrp1.deja.com>
X-Deja-AN: 679849676
References: <39E35A22.2748A7F6@roirex.dk>
X-Http-Proxy: 1.0 x58.deja.com:80 (Squid/1.1.22) for client 192.101.247.177
Organization: Deja.com - Before you buy.
X-Article-Creation-Date: Tue Oct 10 20:00:46 2000 GMT
X-MyDeja-Info: XMYDJUIDmalissa
Newsgroups: comp.lang.java.programmer,dk.edb.programmering.java
X-Http-User-Agent: Mozilla/4.7 [en] (WinNT; I)