Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • PHP Tutorial
  • PHP Exercises
  • PHP Array
  • PHP String
  • PHP Calendar
  • PHP Filesystem
  • PHP Math
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP GMP
  • PHP IntlChar
  • PHP Image Processing
  • PHP DsSet
  • PHP DsMap
  • PHP Formatter
  • Web Technology
Open In App
Next Article:
What's the difference between \n and \r\n in PHP ?
Next article icon

Difference between Exception::getMessage and Exception::getLine

Last Updated : 05 Dec, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Exception::getMessage: The getMessage exception in PHP language is basically used by the programmers to know the Exception message. It means that whenever an exception condition occurs in a code, in order to know the exact meaning and what that exception is all about this function is been used. This function is quite useful for the programmer because it helps him to find the true nature of that exception and using this valuable information he/she can write the correct exception handling code.

Example: In the below code, the getMessage() will get the exception message.

PHP
<?php     try {         throw new Exception(" error message");     } catch(Exception $e) {         echo $e->getMessage();     } ?> 

Output
 error message

Exception::getLine: The getLine exception in PHP language is basically used by the programmers in order to know at which line the corresponding exception has occurred. It means that whenever an exception occurs in a code, this particular getLine() function can find out the exact position of the code where this exception has occurred. This functionality helps at times where we have a huge code and we are unable to find out the location of a particular exception.

Example: In the below code, the getLine() function will get the line at which the exception has occurred.

PHP
<?php     try {         throw new Exception(" error message");     } catch(Exception $e) {         echo "The exception has occurred on line: "               . $e->getLine();     } ?> 

Output
The exception has occurred on line: 3

Difference between Exception::getMessage and Exception::getLine :

Exception::getMessageException::getLine
This function returns the exception message.This function returns the position of the line at which the exception has occurred.
It returns the exception message in string format.It returns the line number in integer format.
It is helpful in all types of codes.It is most helpful in huge codes ie. Codes containing many lines.

Next Article
What's the difference between \n and \r\n in PHP ?

G

gauravgandal
Improve
Article Tags :
  • Difference Between
  • Web Technologies
  • PHP
  • PHP-Questions
  • Web Technologies - Difference Between

Similar Reads

  • Difference between runtime exception and compile time exception in PHP
    The term PHP is an acronym for Hypertext Preprocessor, which is a server-side scripting language designed specifically for web development. It is open-source which means it is free to download and use. It is very simple to learn and use. The files have the extension “.php”. It is an interpreted lang
    3 min read
  • Difference between Interrupt and Exception
    In computer systems, interrupts and exceptions are like signals that tell the CPU to pause what it’s doing and handle something important. They both temporarily stop a running program, but they are not the same. They come from different sources and are used for different reasons. Knowing the differe
    3 min read
  • Difference Between except: and except Exception as e
    In Python, exception handling is a vital feature that helps manage errors and maintain code stability. Understanding the nuances of different exception-handling constructs is crucial for writing robust and maintainable code. This article will explore the difference between except: and except Excepti
    5 min read
  • Difference between die() and exit() functions in PHP
    PHP exit() Function: In PHP, the exit() function prints a message and exits the application. It's often used to print a different message in the event of a mistake. Use exit() when there is not an error and have to stop the execution. Syntax: exit("Message goes here"); or exit(); Example: exit("This
    2 min read
  • What's the difference between and in PHP ?
    There are many types of line-ending characters that are used in PHP. They differ depending upon the operating system and editors using them. It's also based on how apps, libraries, protocols, and file formats deal with things. These characters are invisible. \n is used for the newline or linefeed, w
    2 min read
  • Difference Between Pipes and Message Queues
    When there is a need to design software with a potential for Inter-process Communication (IPC), it becomes very important to select the appropriate strategy. Pipes and Message Queues are basically two of the most typical IPC approaches in a system through which processes can communicate. Although th
    6 min read
  • Difference Between System.out.println() and System.err.println() in Java
    System.out is a PrintStream to which we can write characters.  It outputs the data we write to it on the Command Line Interface console/terminal. It is mostly used for console applications/programs to display the result to the user. It can be also useful in debugging small programs. Syntax: System.o
    2 min read
  • Difference Between System.out.print() and System.out.println() Function in Java
    In Java, we have the following functions to print anything in the console. System.out.print() andSystem.out.println() But there is a slight difference between both of them, i.e. System.out.println() prints the content and switch to the next line after execution of the statement whereas System.out.pr
    2 min read
  • Difference between Compile Time Errors and Runtime Errors
    Compile-Time Errors: Errors that occur when you violate the rules of writing syntax are known as Compile-Time errors. This compiler error indicates something that must be fixed before the code can be compiled. All these errors are detected by the compiler and thus are known as compile-time errors. M
    3 min read
  • Difference between Try, Try?, and Try! in Swift
    In every programming language, exception handling plays a crucial role in ensuring the reliability and stability of code. With the rise of Swift as a powerful and versatile programming language, developers are faced with new challenges and opportunities in managing errors and unexpected events. This
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences