in Education by
The question is: after am raising an exception, can I stop it to propagate from it's own constructor? consider the code bellow: unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TMyErrorClass = class(Exception) constructor Create(aMsg:String); end; TForm2 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.FormCreate(Sender: TObject); begin // raise TMyErrorClass.Create('test'); end; { TMyErrorClass} constructor TMyErrorClass.Create(aMsg: String); begin {$IFDEF DEBUG} Showmessage(aMsg); {$ELSE} //here I want to 'kill' the exception {$ENDIF} end; end. After raise is called, how can I terminate the Exception, without adding try except/finally where I'm raising the exception? LE: I have an app which has almost 2000 raise like this...and I'm trying to find out an alternative solution to write error handling for it.... JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Once you've entered a raise statement, there are only two ways to avoid going through with raising that exception: Raise something else first. From within the constructor of the exception that's about to be raised, you can create and raise a different exception first. That will avoid your program ever reaching the first raise statement. Terminate the thread so nothing gets to run. You can do this various ways, including ExitThread, Halt, and ExitProcess, which are all pretty much equivalent in this context. Your program won't be running anymore, but at least you've prevented it from raising that exception! Neither of those will solve the problem you're trying to solve, but they will do what you asked for in your question. The bottom line is that whatever you're trying to do, quelling an exception after you've already initiated the exception-raising mechanism is the wrong approach. You can't unring a bell, and you can't unraise an exception.

Related questions

0 votes
    The question is: after am raising an exception, can I stop it to propagate from it's own constructor ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    What is effect on neuron as a whole when its potential get raised to -60mv? (a) it get fired (b) no effect (c) it get compressed (d) it expands Please answer the above question....
asked Sep 21, 2022 in Education by JackTerrance
0 votes
    When I'm calling a Dll method it sometimes throws an exception, and sometimes doesn't. I'm calling ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 20, 2022 in Education by JackTerrance
0 votes
    Which of these keywords is not a part of exception handling? (a) try (b) finally (c) thrown (d) ... Exception Handling of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    At least according to a description of Mono's exception handling implementation, all the x86 registers are ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    Which of these keywords is not a part of exception handling? (a) try (b) finally (c) thrown (d) ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    What is Exception Handling in WCF? What are the ways for WCF Exception Handling?...
asked Apr 2, 2021 in Education by JackTerrance
0 votes
    Explain about SAP ABAP - Exception Handling?...
asked Oct 18, 2020 in Technology by JackTerrance
0 votes
    If a robot can alter its own trajectory in response to external conditions, it is considered to be __________ (a) ... open loop (d) non-servo Please answer the above question....
asked Oct 22, 2022 in Education by JackTerrance
0 votes
    If a robot can alter its own trajectory in response to external conditions, it is considered to be __________ (a) ... open loop (d) non-servo Please answer the above question....
asked Oct 2, 2022 in Education by JackTerrance
0 votes
    What is it called if an object has its own lifecycle and there is no owner? (a) Aggregation (b) ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    What is it called where object has its own lifecycle and child object cannot belong to another parent object? ... questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    State whether the following statement are true or false with reasons. Sovereignty means State has the freedom to take its own decision. Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    Is there any reason to keep time series data in its own database, separate from other tables or is ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    According to Kafka Documentation Connector configurations are simple key-value mappings. For standalone mode these are ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
...