---
title: "How to get error line number in c#?"  
description: "How to get error line number in c#?"  
author: "Anonymous User"  
published: 2013-03-06  
updated: 2013-03-06  
canonical: https://www.mindstick.com/forum/627/how-to-get-error-line-number-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to get error line number in c#?

Hi!

Can any one help me?

I want to get on which line [exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling) are generated. Simply I want to [stored](https://www.mindstick.com/forum/157561/what-is-the-stored-procedure-create-a-procedure-to-find-the-record-by-stu_id-from-the-student-table) [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) line number in C#.

Please help me!

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Jacob!

You can try this way!

Create ExceptionHelper class as below

public static class ExceptionHelper\
{\
public static int LineNumber(this Exception e)\
{

int linenum = 0;\
try\
{\
linenum = Convert.ToInt32(e.StackTrace.Substring(e.StackTrace.LastIndexOf(":line") + 5));\
}\
catch\
{\
//Stack trace is not available!\
}\
return linenum;\
}\
}

get error line number as below

try\
{\
// do somthing here\
}\
catch(Exception ex)\
{\
int eln = ex.LineNumber();\
}

I hope it resolve your problem


---

Original Source: https://www.mindstick.com/forum/627/how-to-get-error-line-number-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
