Jump to content

Talk:Exception handling syntax

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ushkin N (talk | contribs) at 09:32, 22 May 2016. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
WikiProject iconComputing Unassessed
WikiProject iconThis article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
???This article has not yet received a rating on Wikipedia's content assessment scale.
???This article has not yet received a rating on the project's importance scale.

BASIC code example

Shouldn't proper BASIC error handling code always use the RESUME statement?

I’m not sure about BASIC, but Visual Basic certainly should. The presented code (trying to emulate stuctured error handling with a lot of boilerplate code) just isn’t the VB way of doing it. What about the following? —Rathgemz (talk) 16:43, 4 October 2010 (UTC)[reply]
Const My_Error = vbObjectError + 132 ' It's the programmer's obligation to keep the error numbers unique
Function f(x as Integer) as Integer
  ' Idiom 1: Ignore errors or test explicitly after each statement
  On Error Resume Next
  Do_Something ' Exceptions from Do_Something are ignored, execution just continues with Do_Something_Else
  Do_Something_Else
  If Err.Number <> 0 Then 
    ' handle errors in Do_Something_Else
  End If
  
  ' Idiom 2: Error Handlers
  On Error Goto Handler
  ...
  Err.Raise My_Error ' Raising an exception
  ...
Good_Restart_Point:  
  ... 
  Exit Function
Handler:
  Select Case Err.Number
    Case My_Error
      ' in case of My_Error, do something here  
      Resume Good_Restart_Point ' then continue with an appropriate statement
    Case 58 ' File already exists
      ' delete file
      Resume ' then restart the statement that failed
    Case 6 ' Overflow
      Result = &H7FFFFFFF ' set to maximum
      Resume Next ' then continue with next statement
    Case Else
      ' Propagate other errors to caller
      Err.Raise Err.Number
  End Select
End Function

Else in C++

Hi,

there is a followin snippet of pseudocode in Exception handling:

try {
 line = console.readLine();
 if (line.length() == 0) {
  throw new EmptyLineException("The line read from console was empty!");
 }
 console.printLine("Hello %s!" % line);
} catch (EmptyLineException e) {
 console.printLine("Hello!");
} catch (Exception e) {
 console.printLine("Error: " + e.message());
} else {
 console.printLine("The program ran successfully");
} finally {
 console.printLine("The program terminates now");
}

in indicates that a program can act in some way when everything went successfully and in a different way if something was broken. I am missing in my knowledge how to make that "if error {} else {}". Could you, please, extend and edit this article (at least for C++) so I can learn how to implement it really? Thank you in advance!

Sorry, not all programming languages support that feature. Looking at the article we have here, it seems only Python and Ruby have else, and that we know of no other name for it either.
However, you should note that all of these features can be written in some other way if the direct way is not available. In some cases, you can put to the end of the try block anything you'd want to put to the else block, because the end of the try block is reached only if there weren't exceptions. --TuukkaH 19:53, 25 April 2006 (UTC)[reply]

The "else" here seems idiotic to me. If I have statements A and B in my "try" block, and C in my "else" block, how does that differ from having A, B and C in the "try" block? —Preceding unsigned comment added by 192.91.171.42 (talk) 20:06, 16 March 2010 (UTC)[reply]

Appropriateness of this page for Wikipedia

Hello. I just tagged this page with {{Unreferenced}}. It doesn't seem to fit the model of an Encyclopaedia article; maybe it should be moved to WikiBooks? —Preceding unsigned comment added by AlastairIrvine (talkcontribs) 07:53, 18 January 2010 (UTC)[reply]

There's some truth and logic in that, but we tend to make an exception for articles on programming language and OS commands (e.g. chmod). Actually this is kind of in the nature of a list article. Tisane talk/stalk 02:42, 29 June 2010 (UTC)[reply]

Throw command

What about the throw command in PHP? Would it be appropriate to list that here? Tisane talk/stalk 02:40, 29 June 2010 (UTC)[reply]

Finally

There are a few cases where "Finally" is said to always be called. This is not true; it is only called if the thread continues to execute. Killing a process or a thread within it will not result in the finally clause being called. 84.12.212.235 (talk) 16:29, 5 December 2012 (UTC)[reply]

Please move

Requested move 21 May 2016

Exception handling syntaxComparison of programming languages (exceptions) – Consistent names in Category:Programming language comparisons 128.70.197.164 (talk) 22:58, 21 May 2016 (UTC)[reply]

Requested move 22 May 2016

Exception handling syntaxComparison of programming languages (exceptions) – Consistent naming in Category:Programming languages by language concept Ushkin N (talk) 09:32, 22 May 2016 (UTC)[reply]

It was used before:

Ushkin N (talk) 09:32, 22 May 2016 (UTC)[reply]