answersLogoWhite

0

an exception object must follow the throw statement. That exception object must be created by new-operator initially. One can throw the same exception instance again without creating a new one (throw new) later.

Just for fun and as an example: Let's on purposely cause 2 operations to throw exception. A third method will determine which operation produce the shorter exception message length, and throw the shorter one.

public void Operation1() { throw new SystemException("From Operation 1"); }

public void Operation2() { throw new SystemException("From Op2"); }

public void GetShorter() {

SystemException e1;

SystemException e2;

try { Operation1(); } catch (Exception e) { e1 = e; }

try { Operation2(); } catch (Exception e) { e2 = e; }

if (e1.Message.Length < e2.Message.Length) {

throw e1; // an example of not using new-operator

} else {

throw e2;

}

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

What is difference between bean builder and net-beans?

it is same .. the new name is NetBeans plz download it from oracle website ..!! another beanbox is also netbeans ....


Can you throw exception from catch block in net?

Yes. Use C# code as an example: try { int k = 100 / 0; // this will throw an exception } catch (Exception e) { throw new SystemException("Throwing a new exception because of "+ e.Message); }


What is the difference between garbage and recycling?

Recycling you can send it so some place and they can make it into something new. garbage it is something that you don't need and you just throw it away.


What is net new borrowing as it relates to determining the cash flow to creditors?

Net new borrowing is the difference of the long-term debt on the balance sheet. Cash flow to creditors = Interest paid - difference of the long-term debt


What is the difference between the mid Atlantic and the new England region?

whats the difference between midAtlantic and new England


What is the difference between malloc and new in terms of throwing exceptions?

malloc will return a 0 if memory is unable to be allocated. new on the other hand will either throw an exception or also return 0, depending on the compiler and the compiler settings.


What is the difference between traditional banking and modern banking?

difference between modern and traditional banking is


What is the difference between the old broadsheet and the new broadsheet?

The difference is that one of them is old and the other one new.


What is the time difference between Adelaide and New York city?

Difference in local time in Adelaide and Singapore


What are the difference between Karachi and New York?

similarities and differences between new York and Karachi


What is the difference between New York and Chennai?

9 . 5 hrs is the difference


What is the difference between bone China and new bone China?

The difference is the spelling.