Click here to Skip to main content
15,915,336 members
Home / Discussions / C#
   

C#

 
Generali see why C# SHOULD have required to catch exceptions now Pin
vista2712-Sep-04 12:00
vista2712-Sep-04 12:00 
GeneralRe: i see why C# SHOULD have required to catch exceptions now Pin
Colin Angus Mackay12-Sep-04 13:52
Colin Angus Mackay12-Sep-04 13:52 
GeneralRe: i see why C# SHOULD have required to catch exceptions now Pin
Alex Korchemniy12-Sep-04 20:29
Alex Korchemniy12-Sep-04 20:29 
GeneralRe: i see why C# SHOULD have required to catch exceptions now Pin
Colin Angus Mackay12-Sep-04 22:20
Colin Angus Mackay12-Sep-04 22:20 
GeneralRe: i see why C# SHOULD have required to catch exceptions now Pin
User 12301612-Sep-04 22:38
User 12301612-Sep-04 22:38 
GeneralRe: i see why C# SHOULD have required to catch exceptions now Pin
Christian Graus12-Sep-04 13:52
protectorChristian Graus12-Sep-04 13:52 
GeneralRe: i see why C# SHOULD have required to catch exceptions now Pin
Nicholas Cardi12-Sep-04 13:57
Nicholas Cardi12-Sep-04 13:57 
GeneralRe: i see why C# SHOULD have required to catch exceptions now Pin
Salil Khedkar13-Sep-04 1:26
Salil Khedkar13-Sep-04 1:26 
To answer your questions:

(1) No. NET does not mandate exception handling like Java. One reason I can think of is the performance, try-catch blocks involve extra code being inserted by the compiler around your own code and it has certain performance cost to pay.

(2) Your case about a thrown exception vanishing is very odd. Are you sure it is an exception and not just a logic error? Can you debug and find out where the exception is being ‘eaten out’? Somewhere down the stack an empty catch block like the following must be eating your exception.
catch<br />
 {<br />
 }


(3) I think there is a simple rule of thumb for exception handling:
a. Handle the logic errors with error codes and conditional statements.
b. For exceptional errors with high probability (Internet connection not available for example) have *specific* exception handling logic.
catch(System.Web.HttpException ehttp)<br />
 {<br />
   // Your exception handling code here...<br />
   return false;<br />
 }<br />
 catch(System.Web.SomeotherException eother)<br />
 {<br />
   // Your exception handling code here...<br />
   return false;<br />
 }

c. For exceptional errors with remote probability (e.g. disk out of space) a *universal* exception handler in the main() function or major functions in the code will work well.
catch(Exception e)<br />
{<br />
  // Your exception handling code here...<br />
  return false;<br />
}<br />
catch<br />
{<br />
  // Your exception handling code here...<br />
  return false;<br />
}


This approach will ensure a balance between performance and stability. Any suggestion, friends?
GeneralRe: i see why C# SHOULD have required to catch exceptions now Pin
Salil Khedkar13-Sep-04 1:29
Salil Khedkar13-Sep-04 1:29 
GeneralRe: i see why C# SHOULD have required to catch exceptions now Pin
bjoernen13-Sep-04 2:58
bjoernen13-Sep-04 2:58 
GeneralRe: i see why C# SHOULD have required to catch exceptions now Pin
elguaro12-Oct-04 14:36
elguaro12-Oct-04 14:36 
GeneralRe: i see why C# SHOULD have required to catch exceptions now Pin
bjoernen12-Oct-04 20:08
bjoernen12-Oct-04 20:08 
Generalkeypreview problem ( listview and buttons) Pin
BrownJacket12-Sep-04 10:19
BrownJacket12-Sep-04 10:19 
GeneralListView Problem Pin
Tomas Brennan12-Sep-04 8:50
Tomas Brennan12-Sep-04 8:50 
GeneralRe: ListView Problem Pin
VanesaAFESRG12-Sep-04 17:05
VanesaAFESRG12-Sep-04 17:05 
GeneralRe: ListView Problem Pin
Tomas Brennan13-Sep-04 2:07
Tomas Brennan13-Sep-04 2:07 
GeneralRe: ListView Problem Pin
VanesaAFESRG13-Sep-04 14:42
VanesaAFESRG13-Sep-04 14:42 
GeneralRe: ListView Problem Pin
Tomas Brennan17-Sep-04 5:56
Tomas Brennan17-Sep-04 5:56 
GeneralRe: ListView Problem Pin
SandeepN13-Sep-04 13:05
SandeepN13-Sep-04 13:05 
GeneralRe: ListView Problem Pin
Tomas Brennan17-Sep-04 6:00
Tomas Brennan17-Sep-04 6:00 
GeneralPerformance question Pin
BoxenBiene12-Sep-04 4:21
BoxenBiene12-Sep-04 4:21 
Generalswitch question Pin
BoxenBiene12-Sep-04 3:37
BoxenBiene12-Sep-04 3:37 
GeneralRe: switch question Pin
Dennis C. Dietrich12-Sep-04 4:02
Dennis C. Dietrich12-Sep-04 4:02 
GeneralRe: switch question Pin
BoxenBiene12-Sep-04 4:26
BoxenBiene12-Sep-04 4:26 
Generalembeding a NumericUpDown column in a datagrid Pin
BaraaSh12-Sep-04 3:30
BaraaSh12-Sep-04 3:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.