PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 4, 2022

[FIXED] How do I create a user defined exception that would system exit if not handled? (Exception class seems insufficient.)

 August 04, 2022     exception, python     No comments   

Issue

The python Exception class is supposed to be used for all user defined exceptions. Documentation also says it is used by all non-system-exiting builtin exceptions. I need to create a user defined exception that will system exit if not handled. In quick tests, calling a method (while not using try...catch) that raises my user defined exception doesn't cause an exit. In debugging, I can see that the exception is 'received' by the python interpreter, but it doesn't cause an exit.


Solution

Are you sure? Exceptions do normally cause the program to exit. The following never reaches the print statement.

class MyError(Exception):
     pass

raise MyError

print("survived")

If you see different results, it must be because you are doing something else. Add your code to your question if you still can't see what you are doing wrong.



Answered By - alexis
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing